BioRod
BioRod

Reputation: 549

WWW::Selenium 'cant find element'

I'm having trouble with WWW::Selenium finding an href.

Here is the HTML element I'm looking for.

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

Here is the Perl code I'm using.

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

Here is the error that WWW::Selenium is outputting.

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

Any tips/help will be greatly appreciated.

EDIT Adding the surrounding HTML to aid in the troubleshooting.

    <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>

Upvotes: 1

Views: 117

Answers (1)

Chankey Pathak
Chankey Pathak

Reputation: 21676

Instead of using hard-coded sleep I would suggest using wait_for_element_present.

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

Upvotes: 1

Related Questions