S
S
sikret2014-09-13 15:46:05
Java
sikret, 2014-09-13 15:46:05

How to click on a button with dynamic locator using Selenium+Webdriver+Java?

how do i click on them? Because ID and XPATH change every time

Answer the question

In order to leave comments, you need to log in

3 answer(s)
D
denizen, 2014-09-14
@denizen

findElementsByXPath() will return a list of found elements that can be looped through.
Those. if, for example, all the Following buttons have the class "button-text following-text", then by passing the string ".//span[@class='button-text following-text']" to findElementsByXPath() , you can get a list of all buttons following on the page.

A
Angry, 2014-09-29
Tester

getDriver().findElement(By.xpath(".//span[contains(text(),'Following')]")).click()
I recommend learning the XPath Axis and various functions like contains(), text() , count() , etc.
https://ru.wikipedia.org/wiki/XPath

S
sikret, 2014-09-15
@sikret

Thanks for the advice ! I tried as you suggested getDriver().findElement(By.xpath(".//span[@class='button-text following-text']")).click(); but fell on this test. There are just a lot of "Following" buttons ... which one it should have pressed and how to press them all in turn and check that they are pressed, that is, then they become "Unfollow".

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question