Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/perl/9.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
Perl WWW::Selenium';找不到元素';_Perl_Selenium - Fatal编程技术网

Perl WWW::Selenium';找不到元素';

Perl WWW::Selenium';找不到元素';,perl,selenium,Perl,Selenium,我在WWW::Selenium查找href时遇到问题 这是我正在寻找的HTML元素 <a href="/auctions?organization_id=2">Sell Products</a> 以下是WWW::Selenium正在输出的错误 Error requesting http://localhost:4444/selenium-server/driver/: ERROR: Element //a[contains(@href, "/auctions?organ

我在WWW::Selenium查找href时遇到问题

这是我正在寻找的HTML元素

<a href="/auctions?organization_id=2">Sell Products</a>
以下是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>

    我建议使用
    等待元素出现,而不是使用硬编码的
    睡眠

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

    不确定,但您可能必须退出
    \?
    ,而且,您可以尝试使用
    组织id=2
    并查看它是否有效。谢谢,我尝试了两种方法:退出?还有就是organization_id=2,同样的问题。是否可以简单地使用xPath?好的,我使用的是firefox的xPath定位器,它说链接的xPath为
    id('menu-main-menu')/x:li[3]/x:a
    ,我将修改代码并发布结果。谢谢@rutter。我添加了Perl代码
    sleep5在导致问题的元素和问题解决之前。执行测试时未加载页面,因此未找到错误。
    
    my $locator = q{//a[contains(@href, "/auctions?organization_id=2")]};
    $sel->wait_for_element_present($locator, $timeout)
    $sel->click($locator);