0
votes

I have a button which is wrapped inside a li element which appears 5 seconds after the other elements have loaded. I have to click on this element but I am unable to access this element using selenium.

I have used implicit wait, explicit wait and fluent wait. Selenium is still unable to identify the element as it terminates with a TimeoutException and NoSuchElementException.

The element in HTML:

<li class="wow zoomIn" data-wow-delay="1.0s" data-reactid=".0.0.0.1.5" style="visibility: visible; animation-delay: 1s; animation-name: zoomIn;">
<button class="pip-icon-new" data-role="none" title="PIP" data-reactid=".0.0.0.1.5.0"/>
<span class="mt10 col-xs-12" data-reactid=".0.0.0.1.5.1">PIP</span>
</li>

Fluent Wait:

Wait wait = new FluentWait(driver)
                   .withTimeout(30, TimeUnit.SECONDS)
                   .pollingEvery(5, TimeUnit.SECONDS)
                   .ignoring(NoSuchElementException.class);

        wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("button[data-reactid='.0.0.0.1.5.0']")));

Explicit Wait:

WebElement myDynamicElement = (new WebDriverWait(driver, 10))
                  .until(ExpectedConditions.presenceOfElementLocated(By.xpath("//*[@id='Home-page']/div[1]/ul/li[5]/button")));
                myDynamicElement.click();

Implicit Wait:

WebDriverWait wait=new WebDriverWait(driver, 20);
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("span[class='mt10 col-xs-12']")));

Am I missing something?

2
Problem could be in your selector. Try with By.cssSelector("button[title='PIP']") - acikojevic
is it inside an iframe? - Fran Montero
@acikojevic Have tried that too. It isn't working. - kaushik3993
@FranMontero No, it isn't inside an iframe - kaushik3993
@kaushik3993, can u try condition presenceOfElementLocated and let me know - NarendraR

2 Answers

0
votes

Based on the steps/data you provided, I guess you would like to click on the button with text PIP. Now looking at the HTML I think we can invoke click() method on the button simply using ExplicitWait i.e. WebDriverWait as below:

WebDriverWait wait = new WebDriverWait(driver, 20);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//li[@class='wow zoomIn']")));
driver.findElement(By.xpath("//span[text()='PIP']")).click();
0
votes

You are identifying by data reactid which looks dynamic. You may want to try identifying the element by title

wait.withTimeOut(15,TimeUnit SECONDS).until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//button[@title='PIP']")));