Selenium 查找具有类和样式可见性的元素 [英] Selenium find element with class and style visibility

查看:30
本文介绍了Selenium 查找具有类和样式可见性的元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用其类名单击一个元素,但请确保我还想检查该元素是否可见,下面是代码.

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();

  1. 可见性语法错误
  2. 无法定位元素异常当我删除并包含(@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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆