I am trying to get HTML from a page after a portion of Java executes and updates the HTML. (I know that Java continues to run while the page is open so there is no way to get the code "after" its finished). I'm trying to get the HTML from this page XBowling.com, you can see that there is a splash message before lanes load. I need to get the HTML after the lanes load so i can then look through the data to get to the Lane and then look through the lane's page data to get scores and what not.
I have been messing around with headerless browsers, I'm currently playing around with Awesomium with little success i can't get it to give me the updated version of the HTML just the original when the page first loads.
(I don't have any code because I don't have anything to show other then failed attempts to get the damn thing to work)
Install Selenium.Webdriver.Domify, Selenium.WebDriverBackedSelenium and Selenium.WebDriver.ChromeDriver using nuget and code something like
using (var driver = new ChromeDriver())
{
driver.Navigate().GoToUrl(url);
var columns = driver.Divs(By.ClassName("col-md-6"));
// here you access the elements using driver object
}
Related
I used Selenium(version 4.1.0) in a C# project.I looked up a lot of information.
This is My code
ChromeDriver driver = new ChromeDriver();
driver.Navigate().GoToUrl("xxxx");
var wait = new WebDriverWait(driver, TimeSpan.FromSeconds(30));
wait.Until(ExpectedConditions.ElementExists(By.Id("xxx")));
context.Response.Write(driver.pageSource);
This is very effective for get full page html until I test https://jp.mercari.com.
It can not get full page.
Is there any other way to get the complated page source?
You aren't getting the get full page html as a lot of the elements are distributed within multiple #shadow-root (open) elements.
Conclusion
Even after the webpage compltes rendering the HTML DOM, the entire pageSource may not be available. To access the entire DOM Tree you have to use Document.querySelector().
Hi what I like to do is:
Create in WPF xaml a Grid like that: <_Grid Name="gridWeb">
Open a GeckoFX45 Firefox Browser in this Grid (add the created Geckofx Window as Child to the grid)
Automate this exact Browser in my Grid with Selenium.
I have made a lot of researches on that Problem and I found some articles like https://nhabuiduc.wordpress.com/2014/09/18/geckofx-net-webbrowser-setup-and-features/ on how to solve my issue. With that article I had success to solve point 1 and 2 but with old Version of Geckofx.
I have tried out tons of things, but nothing which included all requirements for my Tool.
Does anyone know if this is even possible?
If yes, does anyone know on how to combine all those 3 requirements with an actual version of Geckofx 45?
Is there any particular reasony why you want to add this browser to Selenium IWebDriver? (like e.g. lots existing code written for IWebDriver?)
If not and you simply want to have an automated browser then you can do much more automation using GeckoFx API.
For example:
GeckoWebBrowser Browser => GetBrowserInstanceSomehow();
...
//get element reference
GeckoInputElement textBox =
this.Browser.Document.GetElementsByClassName("inputBox").FirstOrDefault() as GeckoInputElement;
//set value
textBox.Value = "Something";
GeckoHtmlElement btn = this.Browser.Document.GetElementById("submitButton") as GeckoHtmlElement;
//interact
btn.Click();
You can do virtually everything with it - execute scripts, send POST requests, override CSS, evaluate / change / remove nodes, navigate, handle navigation events etc.
We have a page with Telerik RadEditor on a tab strip. There are scenarios when RadEditor contains a lot of html and when doing a post back in order to switch the tab, all its contents is being post back to the server. This results in gigantic performance loss (there are times when post backs are sending tens of MiB of data).
Is it possible to tweak RadEditor in such a way that it does not send its contents over to server on postbacks? Our code-behind does not rely on RadEditors Content property accessor (does not read its content explicitly), only its mutator (its contents are set from within the control's code-behind).
Is it even possible to do such things with any of Telerik controls and if it is, then how do we achieve such result?
It's worth pointing out that we use relatively old Telerik UI version (2013.2.611.35) and we can't switch to a newer version at the moment.
Thank you in advance.
Consider using the ContentUrl of the PageViews. This will let you load separate pages in iframes, so they will postback independently of the main page. Thus, you can have a standalone page with the editor and standalone pages for your other tabs.
On the possibility to exclude something from the POST request - I don't know of a way to do this, as it is not supposed to happen. The whole point is to transfer the current page state to the server.
Another option you may consider is using AJAX and the PageRequestManager's beingRequest event to try to blank out the editor. I have not tried it and I do not know whether it will actually work out, since so much data may simply be too much for the JS engine to process before the postback begins. Here is a bit of code that illustrates the idea:
var currContent = null;
function BeginRequestHandler(sender, args) {
var editor = $find("<%=RadEditor1.ClientID%>");
currContent = editor.get_html(true);
editor.set_html("");
}
function EndRequestHandler(sender, args) {
var editor = $find("<%=RadEditor1.ClientID%>");
editor.set_html(currContent);
currContent = null;
}
Sys.WebForms.PageRequestManager.getInstance().add_beginRequest(BeginRequestHandler);
Sys.WebForms.PageRequestManager.getInstance().add_endRequest(EndRequestHandler);
I have a C# Windows Forms Application with a webBrowser within it. It visits a Wikia chatroom, where it then locates the element which contains the chat output. This element looks like:
<div style="" id="Chat_XXXXX" class="Chat">
<ul>
(chat text)
</ul>
</div>
The purpose of the program is to retrieve the chat text every once in a while for logging purposes. This is easily done by parsing the "InnerHtml" of the "Chat_XXXXX" element. However, I also need to clear the text from the window when I do this (for various reasons, I cannot leave the text in the window). I figured I would just erase the chat text portion of the element, as this is how it is done with a handy javascript file called "chat hacks" for Wiki chat (here). Or at least, I think that's how it does it. If you look at the function "clearWindow" in that file, you can see what it does:
NodeChatController.prototype.clearWindow = function() {
this.viewDiscussion.chatUL.html('');
this.inlineAlert(i18n['cleared']);
}
I have tried setting the InnerHtml of "Chat_XXXXX" using the following three strings (not all at the same time, of course):
HtmlDocument document = webBrowser1.Document;
document.GetElementById("Chat_XXXXX").InnerHtml = ""
document.GetElementById("Chat_XXXXX").InnerHtml = "<ul></ul>"
document.GetElementById("Chat_XXXXX").InnerHtml = "<ul><li class=\"inline-alert\"> Window cleared. </li></ul>"
However, although these clear the window (and in the case of the last one prints a message), the chat no longer updates as new messages show up. The only fix is to reload the page, which isn't an option, because reloading the page brings in a whole load of chat history (which I'm trying to avoid). I've also tried importing that javascript mentioned above into the page using:
HtmlElement head = webBrowser1.Document.GetElementsByTagName("head")[0];
HtmlElement scriptEl = webBrowser1.Document.CreateElement("script");
scriptEl.SetAttribute("type", "text/javascript");
scriptEl.SetAttribute("src", "https://db.tt/66q8UQbY");
head.AppendChild(scriptEl);
This javascript creates a button which clears the chat window. The button clears the window just fine, but again, the chat no longer updates. I know this button works correctly without stopping further incoming chat in "regular" browsers (Chrome, Firefox, Opera, etc). I've used it many times, and the script itself is quite popular in the Wikia community. I've already followed the steps here: "WPF WebBrowser Control - position:fixed Element jumps while scrolling (Windows 8)" to get the browser to act as close as it can (?) to Internet Explorer. I've already checked the Body field of the document after altering the InnerHtml to make sure that my replacements didn't alter anything important. Just for clarity, here's an example of what is contained in the (chat text) portion of my original example:
<li class="you" data-user="UserNameHere" id="entry-c812">
...avatars and junk...
<span class="message">hello</span>
</li>
I honestly have no idea what could be causing the chat element to stop updating after it has been edited (especially since it works outside of this program), so I don't know what information to include. Whatever you need, I'll provide it. Here's the javascript from Wikia which generates the chat output window: chat_js2. Look for "Chat_" to find the part which originally generates the window. I don't know where the output is updated in that file though.
I am trying to get Razor (C#) and javascript to play nicely together but I can't seem to do it. I have searched the other articles on StackOverflow, but none of them seem
to work for me.
Some noticeable differences from other posts and mine include the following:
I am using an external JavaScript file (not mandatory, but it is there).
I am using a cshtml file for the header layout for all pages (which puts the head tag in a different file than the one actually attempting to call the function.
I also use jQuery, if it would be easier that way.
What I am trying to accomplish:
All I need to do is get the contents of a tag (innerHTML, or .html in jQuery) (by id, class, whatever) and assign that value to "AppState["gEntryID"] for use with the next page.
Some things I have tried:
function entryClickHandler()
{
#AppState["gEntryID"] = document.getElementById("tester").innerHTML;
}
AND
function entryClickHandler()
{
<text>
#AppState["gEntryID"] = document.getElementById("tester").innerHTML;
</text>
}
I have tried these (and a few other variations on these) in both the external file and the head section within the HeaderLayout File.
I understand that C# runs before the page and the JavaScript mostly runs after the page (at least with events such as this).
Any help would be greatly appreciated.
It doesn't work that way. You cannot set variables in the C#/Razor side with JavaScript without using a form post or ajax submit.
Javascript doesn't get access to the page until after Razor has done it's part and rendered and sent the page.