Warning: file_get_contents(/data/phpspider/zhask/data//catemap/3/xpath/2.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 python定位器不起作用_Python_Xpath_Selenium - Fatal编程技术网

Selenium python定位器不起作用

Selenium python定位器不起作用,python,xpath,selenium,Python,Xpath,Selenium,当我试图在页面上查找元素时,selenium python会关闭我。我的一些定位器正在工作,而另一些则没有。例如: 这是有效的:sel.get_text(//div[@class='fm-title']) 这是有效的:sel。单击(“链接=方案1”) 但以下所有错误都给了我:找不到元素 sel.单击(//a[@href='pmc/articles/instance/2586675/figure/F10/']) sel.get_属性(“//img[@src large='/pmc/artic

当我试图在页面上查找元素时,selenium python会关闭我。我的一些定位器正在工作,而另一些则没有。例如:

  • 这是有效的:
    sel.get_text(//div[@class='fm-title'])
  • 这是有效的:
    sel。单击(“链接=方案1”)
但以下所有错误都给了我:找不到元素

  • sel.单击(//a[@href='pmc/articles/instance/2586675/figure/F10/'])
  • sel.get_属性(“//img[@src large='/pmc/articles/instance/2586675/bin/nihms61582f10.jpg']@title”)
  • sel.get_属性(“//img[@src large='/pmc/articles/instance/2586675/bin/nihms61582f10.jpg']/@title”)
  • sel.点击(//img[@src large='/pmc/articles/instance/2586675/bin/nihms61582f10.jpg'])
在相关源代码片段上:

<div class="fm-title">Structural Insights into the Mechanism of the PLP Synthase Holoenzyme from <em>Thermotoga maritima</em> 

<a href="/pmc/articles/instance/2586675/figure/F10/" class="icon-reflink figpopup" target="figure" onclick="return startTarget(this, 'figure', 1024, 800)">
    <div class="small-thumb-canvas">
        <div class="small-thumb-canvas-1">
            <img src="/pmc/articles/instance/2586675/bin/nihms61582f10.gif" class="icon-reflink small-thumb" alt="Scheme 1" title="Scheme 1" src-large="/pmc/articles/instance/2586675/bin/nihms61582f10.jpg" />
        </div>
    </div>
</a>
海洋热虫PLP合成酶全酶机制的结构洞察 最终,我要做的是单击我通过src-large属性找到的链接(或者找到具有该src-large属性的元素,然后单击其父元素链接)


我正在Windows XP上使用Selenium Server 2.15.0和python绑定v2.0b3以及Firefox 8.0。

页面url会有所帮助,因为如果url是: -html代码段中的所有src和href属性都不同:

<a href="/pmc/articles/PMC2586675/figure/F10/" class="icon-reflink figpopup"
 target="figure" onclick="return startTarget(this, 'figure', 1024, 800)"
 canvas-rid="_cid___pmc_articles_PMC2586675_bin_nihms61582f10_jpg_">
  <div class="small-thumb-canvas">
    <div class="small-thumb-canvas-1">
       <img src="/pmc/articles/PMC2586675/bin/nihms61582f10.gif"
        class="icon-reflink small-thumb" alt="Scheme 1" title="Scheme 1"
        src-large="/pmc/articles/PMC2586675/bin/nihms61582f10.jpg">
    </div>
  </div>
</a>

如果不是这样的话–有可能在触发
DOMContent
Load
事件后将这些元素添加到DOM中,您需要等待它们,然后才能使用。

我使用的页面URL与您找到的页面相同(它在我的浏览器中加载而不重定向)。事实证明,当Selenium打开该页面时,它会重定向到您找到的URL,而该源中稍有不同的属性是查找这些元素的关键。它起作用了。谢谢!:)