Selenium IDE定位器,用于获取div标记中的背景图像属性
我正在使用Selenium IDE。我需要找到一个如下所示的元素:Selenium IDE定位器,用于获取div标记中的背景图像属性,selenium,Selenium,我正在使用Selenium IDE。我需要找到一个如下所示的元素: <div style="background-image:url('http://www.example.com/img.png');">...</div> (//div[contains(@style,'example.com/img.png')])[1] 。。。 请建议使用xpath/css路径进行相同操作。请尝试以下xpath: //div[contains(@style,'http://ww
<div style="background-image:url('http://www.example.com/img.png');">...</div>
(//div[contains(@style,'example.com/img.png')])[1]
。。。
请建议使用xpath/css路径进行相同操作。请尝试以下xpath:
//div[contains(@style,'http://www.example.com/img.png')]
它将选择div
元素,其style
属性包含文本http://www.example.com/img.png
编辑
根据您的要求,如果您想要获取特定的图像链接,您可以使用上述xpath,如下所示:
<div style="background-image:url('http://www.example.com/img.png');">...</div>
(//div[contains(@style,'example.com/img.png')])[1]
这将按照DOM表示的时间顺序定位第一个div
元素,其中包含example.com/img.png
。同样,如果要定位第二个div
元素,只需将[1]
替换为[2]
,如果是第三个,则替换为[3]
,依此类推
编辑2
- 如果要为PBX规则获取
元素(具有div
作为其背景图像:url(“/images/smart_pattern/event.png”);“
属性的一部分),请使用以下xpath:样式
//div[contains(@style,'http://www.example.com/img.png')]
或//span[.='PBX规则']/following::div[1]
//span[.='PBX rule']/following::div[contains(@style,'images/smart_pattern')]
- 类似地,如果要为Wan测试获取
元素(具有div
作为其背景图像:url(“/images/smart_pattern/event.png”);“
属性的一部分),请使用以下xpath:样式
//div[contains(@style,'http://www.example.com/img.png')]
或//span[.='Wan测试]/following::div[1]
//span[.='Wan测试]/following::div[包含(@style,'images/smart_pattern')]