我正在尝试使用Selenuium :: Remote :: Driver从Perl脚本中的网页下拉列表中选择一个选项但它显示错误为“执行命令时出错:服务器返回错误代码404而D处没有数据:/strawberry/perl/site/lib/Selenium/Remote/WebElement.pm第46行。“ 你能建议我怎么解决它, 提前谢谢..
Webprogram.pl
use strict;
use warnings;
use Selenium::Remote::Driver;
use Selenium::Remote::WebElement;
use Time::HiRes qw(sleep);
my $driver = new Selenium::Remote::Driver;
$driver->get("https://api.clickandbuy-t2.com/api-testclient/");
$driver->set_implicit_wait_timeout(40000);
my $title2 = $driver->get_title;
print $title2;
my $x=is($driver->get_title,'ClickandBuy PAY API Test Tool',"Title");
print $x;
if ($x==1)
{
print"api test client is opened";
my $sd="S1";
$driver->find_element('mainForm:connectURL','id')->set_selected($sd)->click();#error shown for this command
}
输出为“ClickandBuy PAY API Test Toolok 1 - Title 1api测试客户端打开执行命令时出错:服务器返回错误代码404,D处没有数据:/strawberry/perl/site/lib/Selenium/Remote/WebElement.pm第46行。“
答案 0 :(得分:1)
我对perl不太熟悉,但是当从下拉列表中选择选项时,其他webdriver实现表现得很有趣,您不需要执行set_selected步骤,只需通过使用xpath查找选项直接单击该选项:
$driver->find_element("//select[@id='mainForm:connectURL']/option[@value='".$sd."']")->click();