I am trying to automate a web based application and I am having trouble finding buttons in order to click on them.
Basically there are a number of text boxes on a screen and next to each text box is a "Go" button. Once you hit the "Go" a popup will be overlayed on the screen saying "Are you Sure?" and 2 buttons Yes/No. Where I am getting stuck is after the first set of buttons on the Yes/No popup buttons. Each button has a non-unique class name and no name variable, so I am finding each button by its tagName and then clicking on the relevant element
WebElement aButtons = driver.findElements(By.tagName("button");
aButtons .get(x).click();
This works until aButtons .get(x).click(); throws an exception saying the element isn't clickable. On further inspection of aButtons it has a size of 78 elements, despite there being only 33 visable buttons on the page.
Does anyone have a suggestion on how to find my buttons better? Or perhaps how to handle the exception such that I can, with a bit of trial and error, find the element? If the exception could be ignored, I could probably use a for loop in increments of 10 in order to find which element the Yes/No buttons correspond to.
If I ruled the world I would go to the developer of this webpage and ask them to make the buttons more easily identifiable, but that unfortunately is out of the question
When I inspect the elements in question this is the block in the html that gets highlighted
"Go" button:
<
button type "submit" ng-click="vm.click()" ng-disabled = "vm.isDisabled()"
class = "btn btn"> Generate <button/
>
<
button class ="btn" ng-show="vm.runScripts" ng-click="vm.runScript()" ng-
disabled ="vm.runScript.isScriptRunning">
>span class = "glyphicon play" aria-hidden="true"></span>
Yes
</button>
I was having trouble with the formatting of the above since I am unfamiliar with posting html code.v the 2nd button is the yes button.
(Note the "No" button has the same "btn" class name). When I tried to find the element based off of the class name " glyphicon play" I got an error saying compound class names are not valid. I was able to find the "Go" buttons since they were sequential, so like aButtons .get(1).click(); was the first Go button on the page, aButtons .get(2).click(); was the second etc.
I cannot share the url since it is an internal site.
Related
when I open a particular webpage it has a EULA form that appears on top of the home page in the form of a modal in HTML/CSS. I have tried the XPath of the accept button but it says element not found also tried using handle alert.
is there a unique way to handle a dialogue box in robotframework?
image of HTML in inspect view
SeleniumLibrary.Set Focus To Element ${button_on_popup_page}
SeleniumLibrary.Click Element ${button_on_popup_page}
I figured it out, shown in the above code. I first set focus to the button and then used the click element. This seemed to work.
There is some kind of Shopping Cart in which you have Product positions.
There is a Button in web dynpro which is supposed to copy the text from the Inputfield from one position to the others.
When I click one of the positions, and enter a text in the inputfield and click on copy to all other positions - it doesn't copy.
Only if I click the button twice it copies the position to the others. What am I doing wrong?
I'm not a web dynpro expert.
Could be an IE bug or some problem in the code.
You can check the onAction property of your button and also check if there's any loop in the events that could probably cause this "only for the second click" behavior.
Please share your Controller/View code so we can provide a complete answer.
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()]"
The code below is shown in firebug for the OK button in the popup of my application
<button id="ext-gen219" class="x-btn-text" type="button">
OK
</button>
Here the button id is randomly generated and also the position of ok button is not identifiable. Is there a way to click on the button by its text? Like the button contains a text called OK.
For Selenium IDE or Selenium RC, xpath=//button[contains(., 'OK')] ought to be a good locator.
I am going on the premise that the text of the popup boxes are not identical so I would recommend something like this:
List<IWebElement> dialogBox = driver.FindElements(By.Class("dialogBoxClass");
int buttonIndex = dialogBox.FindIndex(i => i.FindElement(By.Class("DisplayedTextElementClass").Text.Contains("some unique text here"));
dialogBox[buttonIndex].FindElement(By.ClassName("x-btn-text")).Click();
This captures the parent element of all the dialog boxes and then parses each object to find the index of the box you want and then clicks on the 'Ok' button in the correct object.
In case of a submit button this locator css=input:submit[value="OK"] should work. In case of a button element take css=button:contains("OK").