Luca9984 Luca9984 - 1 month ago 6x
HTML Question

Java Selenium: Get get multiple WebElements of the same class

This is the Button I want to press:

<button class="ProfileTweet-actionButton js-actionButton js-actionRetweet" data-modal="ProfileTweet-retweet" type="button">

The same kind of Button exists multiple time on the site.

I tried pressing it by doing this:

By byaXpath = By.xpath("//div[contains(@class,'ProfileTweet-actionButton js-actionButton js-actionRetweet')]");

WebElement Element = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(byaXpath));;

But after 10 secons I just get this error:

org.openqa.selenium.TimeoutException: Timed out after 10 seconds waiting for presence of element

Im kinda lost now. I tried diffrent solution to similar cases but nothing seems to work.


You have to put button instead of div at the start of your xpath.

"//button[contains(@class,'ProfileTweet-actionButton  js-actionButton js-actionRetweet')]"