I am trying to get the Y scroll index for a web page in the WebBrowser control but I can't access the values for the built in Scroll bar.
Any Ideas?
For IE in standards mode (with a doctype, as you say) scrollTop is a property of the <html> element, not the <body>:
HtmlDocument htmlDoc = this.webBrowser1.Document;
int scrollTop = htmlDoc.GetElementsByTagName("HTML")[0].ScrollTop;
(A nicer way to get to the <html> element would be good, if anyone knows of one.)
are you trying to target an HTML element to bring it into view? If that is what you are after you can do this...
htmlDoc.GetElementById("tag_id_string_goes_here").ScrollIntoView(true);
true aligns it with the top and false with the bottom of the element. You can also use ScrollRectangle to get the dimensions of the scrollable region.
WebBrowser1.Document.Body.ScrollTop;
WebBrowser1.Document.Body.ScrollRectangle.Height;
Related
When I inspected for a scroll bar it pointed the element .x-table-container, tried to scroll with the following code, but it's not working, is there any other solution for this?
protected void DragAndDropToVertical(IWebElement webElement, int dragValue)
{
new Actions(Driver).DragAndDropToOffset(webElement, 0, dragValue).Build().Perform();
PauseExecution(200);
}
The problem with Action chain it is usually not working when there is an iframe html in main body or element is not in view. So i think you should use Javascript Execute instead, this usually work best for me. Try it your self:
WebElement element = driver.findElement(By.id("find element with id or using what ever you want"));
((JavascriptExecutor)driver).executeScript("arguments[0].scrollIntoView(true);", element);
Thread.sleep(500);
This code will scroll until it find your element.
Reference
Scroll Element into View with Selenium
I would like to get the font-size for an html element in a web page, for example a <p> tag.
This should be valid even for element without a style or class attribute, so it has to know dynamically inherited css attributes.
I've tried with html agilitypack, a very good lib, but of course it doesn't consider css rendering. Tried also with WPF webbrowser, but it seems it cannot get font size for every element, and for many of them it returns a percentage.
Javascript getComputedStyle() is not suitable since all should run server side.
Any ideas?
Try this:
Element.prototype.getStyle = function (prop) {
if (document.defaultView)
return document.defaultView.getComputedStyle(this, null)[prop];
else
return this.currentStyle[prop];
}
call:
document.getElementById("div1").getStyle("font-size");
I am using a 2 web browsers to compare texts, and when the lines become to long it wraps my text, i would like to remove this or lower my font size to avoid this.
Can some one please advise me on how to remove the word warp or change font size on web Browsers?
The word wrap below totally miss alines my compare:
As far as I know, there is no property of the web browser control that can do this. The presentation of the web page is controlled entirely by the web page itself.
If you cannot change the web page itself, the best you can do is to possibly cache a local version and change its styling using WebBrowser.Document.ExecCommand(). WebBrowser.Document.InvokeScript() also works but requires already-defined JS, so we have to go ahead and add in the script manually.
HtmlElement head = webBrowser.Document.GetElementsByTagName("head")[0];
HtmlElement script = webBrowser.Document.CreateElement("script");
IHTMLScriptElement element = (IHTMLScriptElement)script.DomElement;
element.text = "function adjust { document.getElementById('yourIdHere').style.whiteSpace='nowrap'; }";
head.AppendChild(script);
webBrowser.Document.InvokeScript("adjust");
Just find the div id of the text by looking at the web page's source code and you should be golden. If it doesn't have a div id, you can use other JS methods (such as getElementsByTagName) to find it.
You can not adjust font size or wrapper text from the web control its self. So you should adjust the styling of the elements inside the web browser.
I adjusted the styling at the same place i styled the green and red highlighting.
html.Append("<ins style=\"white-space:nowrap; display:inline; background:#e6ffe6;\">")
.Append(text)
.Append("</ins>");
"white-space:nowrap; display:inline;
The above code is what i added to remove word wrapping.
Inspired by Pomster's Answer, that's what I did to get the best result:
String.Format("<div style='white-space:nowrap; display:inline;'>{0}</div>",text);
c# 6.0 version:
$"<div style='white-space:nowrap; display:inline;'>{text}</div>";
I am having the following problem:
I have a web page hosting silverlight content. The silverlight content is navigation aware, so it will always be the same html page and the same silverlight control. The content however will of course change when the user is navigating from one page inside the control to another.
Different pages have different size requirements and in some cases the final height of the content is unknown because the content is coming from a web service.
I want the height of the silverlight content to be dynamically according to what it actually needs. I saw many solutions to make the silverlight control fit the browser window, but I want the silverlight content to only have the actual height it needs and overflow when necessary, so that I can use the browsers scrollbars.
The page should also have a static background image, which is giving me some problems when the object tag is not exactly the size of the silverlight content.
The effect I want to achieve is more or less like in this web page:
http://www.codegarden.de/
The background should be in the html page when possible and the silverlight control should be the content in the middle part and should scroll with the browser scrollbar.
Can anyone help me? Thanks!
You can have your silverlight application execute javascript commands on the hosting page, that will in turn set the size of the <Object> tag.
Something like that:
using System.Windows.Browser;
// set a global variable
HtmlPage.Window.Eval(String.Format("setSilverlightObjSize({0},{1});",newW,newH));
where setSilverlightObjSize is a javascript function you wrote in the hosting page.
soemthing like:
function SetObjectTagProps(w,h)
{
var obj = document.getElementById("silverlightObj");
obj.width = w;
obj.height = h;
}
I know when i want to scroll down to specific element in appium use the following
driver.ScrollTo(value);
but this value is changed every time and can't detect it i can not use this value to scroll until find the element, but this element is the last element in my page and number of element in the page is changed between user and another.
So, there is any other way to scroll down till the end of the page ?
Use xpath to find the element without using value(as it is dynamic)
then use that element to scroll,
WebElement element = driver.findElementByXpath("xpath_of_element");
((JavascriptExecutor) driver).executeScript("arguments[0].scrollIntoView(true);", element);
Just post the DOM of that page..i'll give you efficient xpath so even if your dom is dynamic that locator will work...
scrollToExact and scrollTo method is depricated since JAVA client version 4.0.0 (https://github.com/appium/java-client/blob/master/README.md).
You can use UiScrollable and UiSelector and their methods to scroll any page (https://developer.android.com/reference/android/support/test/uiautomator/UiScrollable.html).
Example of JAVA code (please edit it with C# syntax):
#AndroidFindBy (uiAutomator = "new UiScrollable(new
UiSelector()).scrollIntoView(new UiSelector().textContains(\"Question
\"))")
If you want scroll to the bottom of page, please create method that will do several steps to find last element of page, otherwise you will get an error (Element not found)
Use touch action instead
TouchAction t = new TouchAction(driver);
t.longPress(element(source)).moveTo(element(destination)).release().perform();