WebElement可以在浏览器中使用cssSelector,xpath定位,虽然它不是null,但它是NotPresent,NotClickable,NotEnabled

问题描述 投票:1回答:1

这可能是Selenium问题或Angular问题。我不知道..我有一个带有以下HTML代码的按钮元素。不过,这是一个有棱有角的网站。

<div class="col-xs-12 col-sm-3 col-sm-push-6 col-lg-3" css="1">
<button class="btn btn-secondary pull-right" style="background-color: #00A6CA; border-color:#00A6CA;" type="button">
<span aria-hidden="true" class="fa tufa-plus-circle-o" style=""></span>
NEW EXTRACT 
</button>
</div>

我使用xpath作为//按钮[contains(text(),'NEW EXTRACT')]和css Selector为'button.btn.btn-secondary.pull-right'。两者都很好地识别了浏览器控制台中的一对一(不是多个)按钮。当我在页面对象代码中使用它们中的任何一个时...

System.out.println("@@@@@@@@@@@ is NOT null> "+(newExtractBtn != null));
System.out.println("@@@@@@@@@@@ to string> "+newExtractBtn.toString());
System.out.println("@@@@@@@@@@@ is present> "+newExtractBtn.isPresent());
Thread.sleep(10000);
System.out.println("@@@@@@@@@@@ Thread sleep for 10sec");
newExtractBtn.waitUntilEnabled();
System.out.println("@@@@@@@@@@@ waited until enabled");
newExtractBtn.waitUntilPresent();

输出为......

I am getting out put as 
@@@@@@@@@@@ is NOT null> true
@@@@@@@@@@@ to string> ExtractExecutionHistoryPage.newExtractBtn
@@@@@@@@@@@ is present> false
@@@@@@@@@@@ Thread sleep for 10sec

一旦它击中webelement对象**newExtractBtn**,它就会抛出以下消息。

> net.thucydides.core.webdriver.exceptions.ElementShouldBeEnabledException: Expected enabled element was not enabled
> Caused by: org.openqa.selenium.TimeoutException: Expected condition failed: waiting for ExtractExecutionHistoryPage.newExtractBtn to be enabled (tried for 5 second(s) with 100 milliseconds interval)

为什么webelement newExtractBtn可以在浏览器中找到xpath,css并且在网页上可见并且也是可点击的在运行时不存在且不可点击?

java angular selenium selenium-webdriver selenium-chromedriver
1个回答
0
投票

两件事情...

1)你在做一个假设。由于按钮未被“启用”而导致测试失败,因此它从不测试它是否存在。既然css和xpath找到它,它就存在了,但你的代码从来没有这么远。

2)仅仅因为存在按钮,并不意味着它已启用。 JavaScript可以禁用按钮,直到满足某些条件。在输入和验证所有值之前,启动一个禁用“提交”按钮的页面并不罕见。

© www.soinside.com 2019 - 2024. All rights reserved.