无法找到元素并单击按钮

时间:2018-05-04 09:52:26

标签: selenium

<button ng-if="(trans_head == 'N') &amp;&amp; (totalDocValueCount != totalDocVerifiedCount) &amp;&amp; (document_name != 'Select Document')" type="submit" class="btn btn-success btn-xs pull-right right10 ng-scope" data-target="#verificationConfirmationWindow" data-toggle="modal">
                <i class="fa fa-check"></i>
                Verify document
</button>

这是我的HtML代码。我试图找到“验证文档”按钮但无法单击并找到它。

我也试过XPath并且:

WebElement element = driver.findElement(By.xpath("//button[@type='submit']")); 
JavascriptExecutor js = (JavascriptExecutor)driver; 
js.executeScript("arguments[0].click();", element); 

上面的代码没有给出任何例外但也没有定位。

2 个答案:

答案 0 :(得分:0)

使用此Xpath://button[text()='Verify document']

代码driver.findElement(By.xpath("//button[text()='Verify document']")).click();

答案 1 :(得分:0)

使用以下代码:

WebDriverWait wait = new WebDriverWait(driver, 10); 
WebElement button = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(".btn.btn-success.btn-xs.pull-right.right10.ng-scope[type='submit']")));
button.click();

PS:如果元素在iframe内,则在执行操作之前切换到该元素。

希望它可以帮到你!

相关问题