Selenium 查找具有类和样式可见性的元素 [英] Selenium find element with class and style visibility
问题描述
我正在尝试使用其类名单击一个元素,但请确保我还想检查该元素是否可见,下面是代码.
I am trying to click a element using its class name but just be sure i also would like to check if the element is visible below is the code.
<代码>1.driver.findElement(By.xpath("//div[contains(@class,'" +Search.SearchType+ "') and contains(@style, '" +visibility: visible+ "')]/div/div[contains(text(),'查找被保险人')]")).click();
2. driver.findElement(By.xpath("//div[contains(@class,'" +Search.SearchType+ "') and contains(@visibility, 'visible')]/div/div[contains(text(),'Find Insured')]")).click();
- 可见性语法错误
- 无法定位元素异常当我删除并包含(@visibility,'visible')"部分时它工作正常
推荐答案
@Brantley: Selenium 的 isDisplayed()
api 就是为了这个目的,无需解析 'style' 属性.
@Brantley: Selenium's isDisplayed()
api is just for this purpose, to check visibility of element by not having to parse the 'style' attribute.
这篇关于Selenium 查找具有类和样式可见性的元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!