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']"
Related
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();");
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();");
Using C#, ASP.Net
In my webpage i have the link for the another web page, if i click the link that should display a another page inside the main page like child page.
Another webpage should display like a popup window in my webpage. And also size of the another webpage should be small. How to do this.
Need Help.
For displaying one web page within another look at using frames (or an inline frame - iFrame)
The second part of your question I think is asking to be able to display the link in a separate window. To do this, use the target="blank" attribute in the anchor tag. to set the size of the child window you will need to use javascript:
<script type="text/javascript">
function showPopup(url) {
newwindow=window.open(url,'name','height=190,width=520,top=200,left=300,resizable');
if (window.focus) {newwindow.focus()}
}
</script>
So just call the showPopup method from your anchor click event
link text
Ideally you would move the javascript so that it is no longer inline, but this should work.
For the first part you need a master page
For the second part you might need a modal popup or it's jQuery equivalent
However, I don't understand what you mean with
And also size of the another webpage should be small. How to do this.
Another webpage should display like a
popup window in my webpage. And also
size of the another webpage should be
small. How to do this.
Did you mean a jQuery Modal Window?