").isEnabled()){-6ren">
gpt4 book ai didi

testing - 如何使用氦气检查启用和禁用按钮?

转载 作者:行者123 更新时间:2023-11-28 20:54:32 24 4
gpt4 key购买 nike

enter image description here

附加按钮的代码是:

<div style="position: absolute; right: 0; top: 0;">
<button class="prev btn btn-warning disabled" style="padding: 4px 8px;">
<i class="fa fa-chevron-left" style="margin: 0"/>
</button>
<button class="next btn btn-warning" style="padding: 4px 8px;">
<i class="fa fa-chevron-right" style="margin: 0"/>
</button>
</div>

如何使用氦气检查启用了哪一个我尝试了以下代码

        click("Home");

if(Button(">").isEnabled()){
click($("html/body/div[6]/div/h3/div/button[2]"));
}

else{
click($("html/body/div[6]/div/h3/div/button[1]"));
}

但是出现如下错误

Exception in thread "main" org.openqa.selenium.NoSuchElementException:Cannot find element ButtonImpl(">").For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.htmlBuild info: version: '2.45.0', revision: '5017cb8e7ca8e37638dc3091b2440b90a1d8686f', time: '2015-02-2709:10:26'System info: host: 'Keya-PC', ip: '172.16.0.144', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version:'1.8.0_25'Driver info: driver.version: unknownat com.heliumhq.api_impl.GUIElementImpl.perform(GUIElementImpl.java:107)at com.heliumhq.api_impl.GUIElementImpl.bindToFirstOccurrence(GUIElementImpl.java:94)at com.heliumhq.api_impl.GUIElementImpl.getFirstOccurrence(GUIElementImpl.java:89)at com.heliumhq.api_impl.ButtonImpl.isEnabled(ButtonImpl.java:26)at com.heliumhq.API$Button.isEnabled(API.java:1276)at searchHomePage.search(searchHomePage.java:30)at mainClass.main(mainClass.java:19)

最佳答案

错误:找不到元素 ButtonImpl(">")

我们需要检查类(prev btn btn-warning disablednext btn btn-warning)在代码中的存在。

元素“>”在页面上不是图片。

更新:

if (driver.findElements(By.xpath("someXpath")).size == 0)

$(By.xpath("someXpath")).shouldNotBe(visible);

Java 代码:

public static boolean isElementPresent(By by) {

try {
driver.findElement(by);
return true;
} catch (NoSuchElementException e) {
return false;
}

}

关于testing - 如何使用氦气检查启用和禁用按钮?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30589818/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com