Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Selenium IDE定位器,用于获取div标记中的背景图像属性_Selenium - Fatal编程技术网

Selenium IDE定位器,用于获取div标记中的背景图像属性

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

我正在使用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://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')]


谢谢Subh,我现在能够找到元素,但还有一个问题,我有相同的标签,在同一网页上的其他几个地方使用相同的图像链接。example.com/img.png');“>………@Avinash:请在编辑标题下查看我在以上答案中的回答。希望这能帮助您解决问题。!再次感谢Subh,但Selenium无法找到所需元素。您确定[1]、[2]的用法吗…?是否有其他方法来区分所有属性相同的标签?是的..我非常确定..我已经在上面再次编辑了我的答案..我猜文本有点不对劲。请再次检查并让我知道..如果仍然不起作用,请使用Firepath in上传已检查元素的屏幕截图,并在此处添加链接。它届时将更容易解决您的问题。抱歉,Subh,它不起作用。我已上载所需的已检查元素的屏幕截图。链接: