2015-10-19 111 views
1

我在WWW :: Selenium找到href时遇到问题。WWW :: Selenium'找不到元素'

这是我正在寻找的HTML元素。

<a href="/auctions?organization_id=2">Sell Products</a> 

这是我使用的Perl代码。

$sel->click('//a[contains(@href, "/auctions?organization_id=2")]'); 

这是WWW :: Selenium输出的错误。

Error requesting http://localhost:4444/selenium-server/driver/: 
ERROR: Element //a[contains(@href, "/auctions?organization_id=2")] not found 

任何提示/帮助将不胜感激。

编辑 添加周围的HTML以帮助进行故障排除。

<li class="menu-item menu-item-type-custom menu-item-object-custom menu-item-has-children"> 
     <a href="/auctions?organization_id=2">Sell Products</a> 
    </li> 
</ul> 
<ul class="sub-menu"> 
    <li class="menu-item menu-item-type-custom menu-item-object-custom"> 
     <a href="/dashboard?_tab=seller">Seller Dashboard</a> 
    </li> 
</ul> 
+0

不确定,但您可能必须转义'\?',并且您可以尝试使用'organization_id = 2'并查看它是否有效。 –

+0

谢谢,我试过两种:逃避?并只是organization_id = 2,同样的问题。 – BioRod

+0

是否可以简单地使用xPath? – AutomatedOrder

回答

0

,而不是使用硬编码sleep我会用wait_for_element_present建议。

my $locator = q{//a[contains(@href, "/auctions?organization_id=2")]}; 
$sel->wait_for_element_present($locator, $timeout) 
$sel->click($locator);