如何使用氦气检查启用和禁用按钮?
How do I check enable and disabled button using helium?
附加按钮代码为:
<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.html
Build info: version: '2.45.0', revision: '5017cb8e7ca8e37638dc3091b2440b90a1d8686f', time: '2015-02-27
09: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: unknown
at 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(">")
我们需要检查是否存在 class(prev btn btn-warning disabled or next btn btn-warning ) 在代码中。
页面上的元素“>”不是图片。
UPD:
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;
}
}
附加按钮代码为:
<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.html Build info: version: '2.45.0', revision: '5017cb8e7ca8e37638dc3091b2440b90a1d8686f', time: '2015-02-27 09: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: unknown at 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(">")
我们需要检查是否存在 class(prev btn btn-warning disabled or next btn btn-warning ) 在代码中。
页面上的元素“>”不是图片。
UPD:
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;
}
}