When trying to automate our application, there are two buttons with same name.
I'm not able to find a way to recognize these. Please let me know what could be the other ways to identify these elements in selenium webdriver in java
Answers 1 : of How to access the second element that has the same class name in selenium using java. You can use xpath indexing option.
We can get text from multiple elements with the same class in Selenium webdriver. We have to use find_elements_by_xpath(), find_elements_by_class_name() or find_elements_by_css_selector() method which returns a list of all matching elements.
findElements(By. linkText("Services"));; li. get(1). click();//If there are only two such element, here 1 is index of 2nd element in list returned.
You can use xpath indexing option.
By.xpath("(//input[@name='Button'])[2]")
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With