I have <input id="test" disabled="">
. How can I find this element with an attribute disabled="".
PS I don't need to use id in this case. I want to find an element with the disabled attribute.
I've tried to use
String enbl = Login.driver.findElement(By.cssSelector("input#test")).getAttribute("disabled=''");
But I've got the null result
One idea would be using an XPath. Something like this:
By.xpath("//input[@id = 'test'][@disabled = '']")
You can probably do it with CSS selectors too, though I don't know the syntax there.
With xpath
//input[@id='test'][@disabled='']
With css
[id='test'][disabled='']
Note: There is a chance that you need to add additional wait before searching for the element
You can also use the xpath like this:
//input[@id='text' and @disabled='']
Or, if you just want to test, if the element is enabled or not , as @mystarrocks suspects, you can use the below code:
WebElement ele = driver.findElement(By.xpath("//xpath of the element"));
if(ele.isEnabled())
System.out.println("Element is enabled");
else
System.out.println("Element is disabled");
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.