简体   繁体   English

Selenium 中可见、启用或选定的元素

[英]Visible, enabled or selected element in Selenium

I'm a little confused and I dont really know what would it be the best way to go.我有点困惑,我真的不知道 go 的最佳方式是什么。

I'm trying to determine whether an element is visible, enabled or selected.我试图确定一个元素是否可见、启用或选择。 I was thinking about these 3 options:我在考虑这三个选项:

a)Boolean button = driver.findElement(By.id(localizadorId)).isDisplayed();
b)Boolean button = driver.findElement(By.id('localizadorId').isEnable();
c)Boolean button = driver.findElement(By.id("localizadorId")).isSelected();

Does it make sense to you?这对你有意义吗? Which one would it be the best way to go and why?哪一个是 go 的最佳方式,为什么?

isDisplayed() , isEnable() and isSelected() are three different methods to validate three distinct stage of a WebElement . isDisplayed()isEnable()isSelected()是验证WebElement三个不同阶段的三种不同方法。


isDisplayed()被展示()

isDisplayed() validates if a certain element is present and displayed. isDisplayed()验证某个元素是否存在并显示。 If the element is displayed, then the value returned is true.如果显示元素,则返回值为 true。 If not, then the value returned is false.如果不是,则返回的值为假。 However this method avoids the problem of having to parse an element's style attribute.然而,这种方法避免了必须解析元素的style属性的问题。 Example:例子:

boolean eleDisplayed= driver.findElement(By.xpath("xpath")).isDisplayed();

isEnabled()启用()

isEnabled() validates if an element is enabled. isEnabled()验证元素是否启用。 If the element is enabled, it returns a true value.如果元素被启用,它返回一个真值。 If not, it returns a false value.如果不是,它返回一个假值。 This will generally return true for everything but disabled input elements.这通常会为除禁用输入元素之外的所有内容返回 true。 Example:例子:

boolean eleEnabled= driver.findElement(By.xpath("xpath")).isEnabled();

isSelected()被选中()

isSelected() method is often used on radio buttons, checkboxes or options in a menu. isSelected()方法通常用于单选按钮、复选框或菜单中的选项。 It is used to determine is an element is selected.它用于确定是否选择了一个元素。 If the specified element is selected, the value returned is true.如果选择了指定元素,则返回值为真。 If not, the value returned is false.如果不是,则返回值为假。 Example:例子:

boolean eleSelected = driver.findElement(By.xpath("xpath")).isSelected();

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM