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.
Related
I am trying to create this simple test where you head to the URL, enter your login credentials and then click the button to sign in. It is doing everything, except for clicking the button. I am trying to doing it by calling up ClassName. Can anyone look at my test and see what I am doing wrong?
public void test_search()
{
var driver2 = new ChromeDriver(#"C:\Users\MyName\Desktop\NUnitTestProject1\NUnitTestProject1\bin\Debug\netcoreapp2.1");
driver2.Navigate().GoToUrl("https://portal.crushdata.com/");
driver2.FindElement(By.Name("Email")).SendKeys("email#email.com");
driver2.FindElement(By.Name("Password")).SendKeys("Password");
driver2.FindElement(By.ClassName("btn bg-teal btn-block btn-lg waves-effect")).Click();
}
This is my classname for my button.
Use CSS selector as shown below:
By.ClassName("btn.bg-teal.btn-block.btn-lg.waves-effect")
Each dot represents a class.
See this page for more info and here is an example from that page:
.name1.name2
Selects all elements with both name1 and name2 set within its class attribute
To click on the SIGN IN button you have to induce WebDriverWait for the desired ElementToBeClickable() and you can use either of the following Locator Strategies:
CssSelector:
new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("button.btn.bg-teal.btn-block.btn-lg.waves-effect"))).Click();
XPath:
new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//button[text()='SIGN IN']"))).Click();
Try making use of the button xpath.
Open the dev tools. Right click on the button you want to be clicked > Select Inspect >Then right click the html in the dev tools window and Copy Xpath from the Copy option.
Then in you code replace FindElement with FindElementByXPath:
driver2.FindElementByXPath("//*xpath/goes/here")).Click();
Given your shared html block, the following XPath will suffice.
//div[contains(#class = "text-center")]//button[contains(#class, 'btn bg-teal btn-block btn-lg waves-effect') and #type = 'submit']
If the driver is still unable to click you should consider the following:
Is the XPath unique? paste the xpath in chrome's devtools search box in the inspect element tab and make sure the provided xpath is targeting the element you are intending. If this is not the case then you should make the xpath more unique.
Is the element in an iframe? if the element is in an iframe the driver won't be able to locate it by default. In such cases you will need to first switch to the iframe and then attempt to locate and interact with the element.
Is the element clickable, visible and enabled? To check these properties first find the element and store in a separate variable and then check the said properties are true.
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 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 doing an automation program. I load a webpage into my windows form and load it in WebBrowser control. Then, I need to click on a link from the WebBrowser programatically. How can I do this? for example:
Google Me
Facebook Me
The above are 2 different conditions. The first element does not have an id attribute while the second one does. Any idea on how to click each programmatically?
You have to find your element first, by its ID or other filters:
HtmlElement fbLink = webBrowser.Document.GetElementByID("fbLink");
And to simulate "click":
fbLink.InvokeMember("click");
An example for finding your link by inner text:
HtmlElement FindLink(string innerText)
{
foreach (HtmlElement link in webBrowser.Document.GetElementsByTagName("a"))
{
if (link.InnerText.Equals("Google Me"))
{
return link;
}
}
}
You need a way to automate the browser then.
One way to do this is to use Watin (https://sourceforge.net/projects/watin/). It allows you to write a .Net program that controls the browser via a convenient object model. It is mainly used to write automated tests for web pages, but it can also be used to control the browser.
If you don't want to control the browser this way then you could write a javascript that you include on your page that does the clicking, but I doubt that is what you are after.