2017-09-14 102 views
0

我有一个按钮,它被包裹在一个li元素中,在其他元素加载后5秒出现。我必须点击这个元素,但我无法使用硒访问这个元素。Web元素没有被硒识别

我已经使用了隐式等待,显式等待和流畅的等待。 Selenium仍然无法识别元素,因为它终止于TimeoutException和NoSuchElementException。

在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> 

流利等待:

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']"))); 

显等待:

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

隐等待:

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

我错过了什么吗?

+0

问题可能是你的选择。尝试使用By.cssSelector(“button [title ='PIP']”) – acikojevic

+0

它是否在iframe中? –

+0

@acikojevic也尝试过。它不工作。 – kaushik3993

回答

0

根据您提供的步骤/数据,我想您想点击文字按钮PIP。现在看HTML我认为我们可以在按钮调用click()方法简单,如下使用ExplicitWaitWebDriverWait

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