I am trying to capture HTML text from a page, in the case of this website more info is loaded dynamically as you scroll. So it is easy enough to capture the first page of text, but have do I get the next. I have the auto scroll part worked out fine like this:
string Java = "javascript:window.scroll(0,";//Builds up logic so screen will scroll by one page each time
string JavaScroll = Java + Scroll + ");";
webBrowser1.Navigate(JavaScroll);
Scroll += 3050;
String Morefriends = webBrowser1.DocumentText;
The problem is, even when I scroll, the Morefriends HTML text still remains the same as the first page, like it is not updating to reflect the HTML text from the new page that was just scrolled to.
Related
How to scroll to the bottom of the license agreement, which will enable the Accept button? The browser itself does not have a scroll bar; only the agreement has it.
I have googled and tried many different solutions and still can not move the scroll bar., at all.
C# code I've tried. I also tried many other and none is working. Anyone has any idea how to make it work?
IWebElement ScrollBar => DriverContext.Driver.FindElement(By.XPath("//div[#class='frm-scrollbar height-with-eula']"));
Actions act = new Actions(DriverContext.Driver);
act.MoveToElement(ScrollBar).ClickAndHold(ScrollBar).MoveByOffset(0, 1000).Release().Perform();
What Im trying to scroll:
Html for the scroll bar section:
Used this to scroll to the bottom of the page. This works for areas where the scroll bar is inside the webpage itself. Used this in multiple pages for scrolling.
EventFiringWebDriver ef = new(Driver);
// cssStr is the css for the area that includes the scroll bar
cssStr = "div[class=\\\"max-h-370 overflow-y-auto pl-24 pr-24\\\"]";
// 10000 or any number depending on scroll distance in pixels
ef.ExecuteScript("document.querySelector('" + cssStr + "').scrollTop = 10000");
IJavaScriptExecutor js = (IJavaScriptExecutor)DriverContext.Driver;
// by is to be constructed and passed
IWebElement ele = Driver.FindElement(by);
js.ExecuteScript("arguments[0].scrollIntoView(true);", ele);
I've got a aspx page that dynamically renders social media sharing links.
The code looks something like this.
System.Web.UI.HtmlControls.HtmlGenericControl newDiv =
new System.Web.UI.HtmlControls.HtmlGenericControl("DIV");
newDiv.ID = "customFB1";
newDiv.InnerHtml = "<div class='fb-share-button' data-href='http://www.website.com/folder/"+custNumber+".html' data-layout='button_count' data-mobile-iframe='true'><a class='fb-xfbml-parse-ignore' target='_blank' href='https://www.facebook.com/sharer/sharer.php?u=http://www.website.com/folder/"+custNumber+".html&src=sdkpreparse'>Share</a></div>";
customFB.Controls.Add(newDiv);
Now the source works perfectly. Unfortunately 80% of the time when the page loads I have to hit F5 (hard refresh) to actually render the html. When I expect the source when its not render, its there, but won't display.
Any thoughts on how I can get the control to render without hitting F5. My customers won't know to hit F5 hah.
Thanks,
I have a WPF WebBrowser control where I need to insert some text (e.g. the selected item coming from a listbox). This way, if the editor contains "When " and the listbox contains "I, You, He" and I click on "You", the editor must contain "When you".
The code I'm using with the ActiveElement is working right now, but I'm finding some weird issues explained below.
HTMLDocument doc;
doc = webBrowser.Document as HTMLDocument;
doc.activeElement.innerHTML += " " + selectedItemFromListboxAsString + " ";
Then, the webbrowser gets appended the selectedItemFromListboxAsString properly, but when I continue typing after that, the new keystrokes go to the next line. In the sourcecode I can see that a </P> tag has been put after the selectedItemFromListboxAsString. No matter if I remove the </P> programmatically, it will insert the new typed content in a new line.
Is there any other way to achieve the same result instead of playing around with the activeElement?
Thanks in advance.
I am trying to change the Tab text when I navigate to a page. I have many many pages so I don't want to go to each page and add a title control. Instead I am trying to change the MasterPage.master.cs so I only have to add that one bit of code.
The following code is close to what I would like MasterPage.master.cs:
Page.Header.Title = this.Page.ToString():
This would display "ASP.shipping_aspx" (page name is Shipping.aspx) but I would like it to display "Shipping".
How can I programmatically change the tab title text so that it changes whenever I navigate to a new page?
string title = this.Page.ToString().Split('.')[1].Split('_')[0];
Page.Header.Title = char.ToUpper(title[0]) + title.Substring(1);
So I am looking for a way to add HTML text to a programmatically created button, or some other control that would accept HTML text and have a on_click_event to capture.
I have a table that I am building dynamically in the codebehind file based upon steps (attendance to a lesson, and the taking of a quiz) that are recorded as complete or incomplete in the database. If a step was not done, I entered a button with a simple X
If the step was done, I just added HTML month and day to the cell.
Attendance to the lesson is a step that can be repeated, so I wanted to make the lesson button look like the styling of a completed quiz, but still capture a 2nd+ attendance point with a click_event.
I am stumped in making a dynamically created button work with my HTML styling. My text style on an ASP.net webcontrol button in a codebehind file is being interpreted as literal text on that button.
Here is the code that fills the cells, either creates the buttons, or adds the text
if(lesson_completed == true)
{
DateTime date = Convert.ToDateTime(lesson);
Button markNewDateComplete = new Button();//System.Web.UI.WebControls.Button Class
markNewDateComplete.Text = "<font style='font-size:50%;color:silver;'>" + date.ToString("MMMM") + "</font><br><font style='color:light gray'>" + date.ToString("dd") + "<font>";
markNewDateComplete.CssClass = "mybtn";
markNewDateComplete.CommandName = lesson_detail_id.ToString();
markNewDateComplete.Click += new EventHandler(this.NewDateLesson_Click);
tc2x.Controls.Add(markNewDateComplete);
}
else
{
DateTime date = Convert.ToDateTime(quiz);
tc2x.Text = "<font style='font-size:50%;color:silver;'>" + date.ToString("MMMM") + "</font><br><font style='color:light gray'>" + date.ToString("dd") + "<font>";
}
Here is what the output looks like on-screen
There are many pages in SO that give insight how to do this in the regular ASPX page, but none that I could find to do this programmatically in a ASPX.cs codebehind file.
In programming there is always another way to do something; so I am looking for a way to add HTML text to a programmatically created button, or some other small control that would accept HTML text and have a on_click_event that I could use as a method back to SQL.
Example of what I want, but this is not for the codebehind file.Font awesome inside asp button