how to click on radio button which is under a expanding tree node in Selenium - selenium

->ABC
. 1
. 2
Here I have select "ABC" first which expands and shows two radio buttons. I have to find this element on a UI page and click on the 2nd radio button.

as for me, to make it simple, I would like to add css class to those radios, so that I can use find_element(css: '.a').click. This is my lazy and yet effective approach.

If both radio buttons belong to same group then they will have same names
You can extract both of them and click on second one
driver.findElements(By.name("common_name_of_radio_button").click();

Related

Selenium RadioButton & Checkbox button values without ID or Name

I am trying to write and read values from radio buttons and checkboxes which id and name values are changing and not fixed. Therefore I cannot use these as identifiers.
Checkout the below image, this shows a list of radio buttons and checkboxes and the inspected element in chrome. Note that the Name and ID underlined in red are not fixed and cannot be used.
Radio Button & Checkbox - Inspect Element from Chrome
Your id is dynamic, you can not use it. There are so many ways to find element.
By.xpath
By.cssselector
By.linktext
By.name
,....
If you want to use selenium you must know at least first two.
visit link
https://devqa.io/selenium-css-selectors/
https://www.guru99.com/xpath-selenium.html

How to click on specific button on a page using selenium, when only button name is present in html?

On a webpage 3 buttons are present and all 3 buttons have same name eg:, 'continue'. In its html no id is present. I need to click on second button.
Also without using xpath locator.
var elements = this.browser.FindElements(By.Name("//*[contains(#name,'continue')]"));
element[0].Click()
The above code clicks the first element of the 3 elements that are returned.
We can also click the element if you have a unique sibling or preceding element.It could help a lot if you provide the original html code.

Can not click on element via TestComplete object mapping

I need to click on a web element, within TestComplete, this element looks like this:
I outlined its boundary using heavy-black line.
The problem is, by default, an element is always clicked in its middle point, and for this element above, clicking its middle point produces no results as it does not click this plus sign.
Within TestComplete, this element can not be broken further down into smaller elements.
I can use Selenium in JavaScript to click it, but is there is an other way?
Thanks
Try using x and y coordinates with the Click method.
SmartBear Click Action
I needed to click a button on my website but TestComplete was only able to identify the parent object which had 3 buttons in it. I was able to use x,y coordinates to press the 3 different buttons in parent object.
Record a script where you click the button and look at the function created to get the coordinates you need.

How can I select always the last radio button?

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()]"

How to allow clicking on row elements in dynatree

I want to render dynatree node with several checkboxes and select any, but when I click on checkbox, happens click on row, how can I disable click on row and enable clicking on elements, located in node?
It is simple. Use from server noLink: true(node title will be span, not a) and don't remove e.preventDefault, because
Make sure that clicks stop, otherwise <a href='#'> jumps to the top