I am using selenium web driver and currently automating a registration form. There are various fields like username,password etc which we have to fill in the details and click on the terms and conditions check box and the account create button gets enabled.
Right now there is some issue with the java script and all my assertions for the create account button is failing. Is there any way I can work on this issue?
possible solution:
apply getAttribute() function to the element you need. And compare data obtained with expected data to be:
WebElement button = driver.findElement(By.xpath(..blablblalb...));
String color= button.getAttribute("color");
//verifyinh that color is that of expected
Assert.assertTrue(color.contains("red"));
Related
Is there any way on how to click a hidden button by an overlapped input text field, for example if you go to www.google.com and enter a text to search for, selenium can not find the "Search Google" button because it is hidden by the autocomplete of the text field.
Thanks.
You can bypass the validation by using #click! instead of #click. Basically, this triggers the click via JavaScript rather than through standard Selenium commands.
browser = Watir::Browser.new
browser.goto('www.google.com')
browser.text_field(name: 'q').set('watir')
browser.button(name: 'btnK').click!
If you are only using Selenium, you can do:
btn = driver.find_element(name: 'btnK')
driver.execute_script('arguments[0].click();', btn)
As discussed in the comments, you could also close the suggestions box before trying to click the button. You can do this by moving focus to any other element - eg the first link on the page. Depending on what you're testing, this may or may not have value.
browser.text_field(name: 'q').set('watir')
browser.link.focus # move focus to any other element so suggestions close
browser.button(name: 'btnK').click
I have a verification page to test by selenium webdriver automation. On the verification page there are always three questions.
But those questions are selected from a pool of questions and so for a single user different questions might appear every separate time he comes to verification page.
So say there are 20 questions in my pool and there are five options (radio answers) for each question, so there are 100 separate radio buttons and each has its separate id/name in DOM.
I am unable to automate this piece of the webpage.
In order to proceed with my testing, I need to always select the last radio button for each of the three questions.
The last radio always contains either "None" or "never" in the label text and radio text label is clickable.
Also the name locator always starts with "1402248" for each radio button.
I am using Page object model in my projet.
Can someone help me to understand how can I identify each radio webelement?
I am using this:
#FindBy (xpath = "//*[#class='radio']//a[contains(text(),'never') or contains(text(),'None')]")
protected WebElement oVerifyIdentityFirstAnswer;
This CSS selector should find all radio buttons that are last of their type inside a parent element
driver.findElements(By.cssSelector("input[type='radio']:last-of-type"))
If your radio buttons are all encapsuled individually, move the last-of-type to that container element:
driver.findElements(By.cssSelector("a:last-of-type" > input[type='radio']))
This returns a list of WebElement, which you can iterate over and click every entry. I wouldn't use the #FindBy annotation by the way, since it often leads to staleness exceptions.
Try changing your Xpath to:
xpath = "//*[#class='radio']//a[contains(text(),'never') or contains(text(),'None')][last()]"
I am working on a ERP application, where I have to click on a search button, after which it will give me list of data.
Want automate that using webdriver
Screenshot
The search tab is empty before the search option.
How to check, whether the data is coming after pressing the search button or not?
If you are getting the data in a tabular form you can use something like:
List<WebElements> tableRows = driver.findElements(By.tagName("tr"));
and then you can check the size and do whatever you want.
I have a custom app report that shows test cases not run for test set. I need to have a button/link upon clicking of which I can enter a test case result. So far the code that I have is opening up the correct test case result window but upon clicking Save it hangs. When I checked the console output for this hanging window it showed that session was unknown. So the question is can this be achieved with custom generated link and pass the session somehow or the approach should be entirely different. Currently I am using 2.0.p5
Here's an app that uses Rally.nav.Manager.create to instantiate a TestCaseResult editor in response to a button click from a grid cell, in turn based on this answer: How to add a custom button on grid and pass row values?
https://github.com/markwilliams970/TestCaseGrid-AddResults
I am able to select the context menu item by providing keyboard input. i just wanted to know whether there is any way to select a context menu item without keyboard input in Selenium WebDriver.
Thank you for your help.
Once you have the ContextMenu displayed via Selenium, you can then use SendKeys to send down key presses until the correct option is selected followed by an enter key. If this isn't working as separate calls try and perform the ContextMenu and all the key presses sequentially using the Action class (eg. build the action sequence and then perform() them).
A list of Java Selenium Key Enums can be found here.