Am trying to access WebElement properties of a table in a webpage. Doing so is causing the page to automatically scroll down.
For Example, get The WebElement using xpath
IWebElement list = Driver.FindElement(By.XPath("//*[#id='BOM Detail Data_data_panel']/div[1]/div[1]/div[3]/table[1]"));
On Trying to access below statement the page is scrolling
bool text = list.Displayed;
How can i stop scrolling?
I don't think you can stop scrolling in WebDriver. It's how it has been designed. it does the native event rather than javascript events it used to do in Selenium RC.
For example, how would you click in element without scrolling down to that element if it's not in view port.
However, if you don't want to scroll when you try to click some element. I think you should you javascript to click on that element.
js.executeScript("document.getElementById('id').click();");
Related
We have a page(URL 2) which is embedded or loaded in Div element(Popup) of another page(master page) when a button is clicked on master page(URL 1).
I am not able to access the elements on this embedded page.
The firepath developer plugin shows, there are two objects (Top Window URL 1 and another with different URL 2). When I try to highlight any element with xpath locator on page 2 URL 2, its not successful as the object/document selected is Top Window. In order to access elements on page 2, the document needs to be changed.
Tried using SwitchTo method but no luck. The embedded page is niether loaded in a separate window nor in Iframe.
SwitchTo method can only be used if another window is opened or Iframe is present on page.
Does anyone have any ideas or solutions to change the document context so that all new commands are sent to this new page 2.
I am using C# bindings v2.53.
Thanks in advance.
Try to use:
driver.SwitchTo().Window(driver.WindowHandles.ToList().Last());
I got the problem and eventually answer to that.
Its really simple. Its simply working out with jquery.
{driver.executeScript("return $('body /deep/ <#yourSelector>')}
this piece of code simply draws the element from shadow DOM and which can be further used to simulate user actions... :)
I am attempting to access a form within a RadWindow. The web page uses window.radopen() to generate an ASP.NET popup. I need to access that popup, edit it, and click a button. Is there a way to do this using Selenium WebDriver?
Specifically, the radwindow contains a textarea with an id of "txtEntries" and a button with and id of "btnAccept". I have tried finding the textarea first, as below, with no luck.
I am currently attempting:
state = wait.Until<IWebElement>((d) =>
{
return d.FindElement(By.CssSelector("div#radWindow #txtEntries"));
});
With failed results.
Yea, there's a way.. Since RadWindow is not an actual window, it makes it significantly easier.
First, use CSS and have a parent selector. Something like,
div#radWindow
Then just add the elements you want to find to that. e.g.
input[type='text'].someclass
then just concatenate them, so it turns into this -
div#radWindow input[type='text'].someclass
which translates in CSS to "first find a div with id radWindow, and find an input that is a descendant of the div, with the type attribute that equals text that has someclass attached.
I have a webkit-sharp WebView which I am using to display HTMLvia the
LoadString method.
The webview is placed in a ScrolledWindow the ScrolledWindow is placed
in a Gtk Window.
I want to be able to tell the WebView to scroll to a specific part
of the HTML. Normally one would do this using an anchor.
I have defined an anchor and some JavaScript to jump to that anchor, I
call the JavaScript via the ExecuteScript method. This does nothing at
all.
I have also tried adding a button to the HTML that calls the
JavaScript. This also does nothing.
Is there something I can do to make this work, to make it so I can
scroll to a known location in the page?
Update: I can make this work by saving the HTML to a file and then loading from there using a URL which tells it to scroll. However I would like to avoid doing that because of the performance hit of writing the page to disk before displaying it.
How are you adding to ScrolledWindow? I am not GTK expert, but have discovered that it works if you call "add" method and does not work if you call add_with_viewport
Also you may not need to execute the javascript. It looks like you control the html page and can easily access the dom element and call click method on the element.Following sample python code looks for anchor with id "one" and scrolls to desired location without calling javascript.
from gi.repository import WebKit
from gi.repository import Gtk
from gi.repository import GLib, GObject
class WebkitApp:
def exit(self, arg, a1):
Gtk.main_quit()
def onLoad(self, view, frame):
doc = view .get_dom_document()
a = doc.get_element_by_id("one")
a.click()
def __init__(self):
win = Gtk.Window()
self.view = WebKit.WebView()
# Signal Connections
self.view.connect("onload-event", self.onLoad)
file = open("/tmp/epl-v10.html")
html = file.read()
self.view.load_string(html, "text/html", "UTF-8", "file:///tmp")
sw = Gtk.ScrolledWindow()
# sw.add_with_viewport(self.view)
sw.add(self.view);
win.add(sw)
win.maximize()
win.connect("delete-event", self.exit)
win.show_all()
app = WebkitApp()
Gtk.main()
The JavaScript to jump to that anchor, doesn't work while the page is still loading, By waiting for the page load to finish (there is an event for it) then running the script I made it work.
Given an element:
<a id='myElement'>I want to scroll to this line</a>
This can be scrolled to with this JavaScript:
document.getElementById('myElement').scrollIntoView();
Which can be executed in a WebView with the ExecuteScript method, e.g.:
_webView.ExecuteScript("document.getElementById('myElement').scrollIntoView();");
I use Selenium Firefox Driver in C#. On the website it test there is a div. When i click the div, it shows the other div that has contenteditable (so it's like input but text is in the inner of the div).
I need to test it with Selenium, but when i click the div the second one is not displayed. And when i try to change the inner of the second div Selenium returns error that it can not interact with invisible elements.
So i tried to use document.evaluate to call JavaScript to find the div with the class name (it has not have id) and to remove the display attribute. But than i have error because since the div is invisible it is not in the DOM.
How to put the text into second div properly from Selenium Firefox WebDriver?
Check the locator you're using to find your first div. Most likely it's incorrect, so you're not actually clicking on the first div and therefore the second one is never becoming visible.
To find a div using its classname, use "css=div[class='className']"
I'm trying to build my first test with selenium and got a problem.
I'm searching for a element, no problem. I can click on it, get the
text in the element... every thing works fine.
But double click on the element just doesn't work. Selenium
clicks in the wrong location. I made a screenshot of this situation:
Screenshot
To find the row i use xpath and search for the text in the cell, but this text is unique(I checked it)
private readonly string _identityPath = ".//td[.= 'All Employees']";
...
mainPage.FindElement(By.XPath(_identityPath)).Click(); //Works(dotted box)
Actions builder = new Actions(mainPage);
IAction doubleClick = builder.DoubleClick(mainPage.FindElement(By.XPath(_identityPath))).Build();
doubleClick.Perform(); //wrong location/element
/*
Actions action = new Actions(mainPage);
action.DoubleClick(mainPage.FindElement(By.XPath(_identityPath)));
action.Perform(); *///wrong location/element
This page is in an iframe and the grid is a dojo component... maybe the problem
comes from there. Any ideas whats wrong? I have no idea where this is coming from. :/
Greets
It is common issue that Actions builder does not work.
Using JavaScript should help - find answer in this thread:
Selenium 2/Webdriver - how to double click a table row (which opens a new window)
If the element is in an iframe, you need to switch to that iframe in order to interact with the element.