2015-10-19 147 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);