如何抑制;警告";使用Selenium::Remote::Driver?
如何获取上述代码而不是以打印此警告: 执行命令时出错:无此类元素:无法定位 元素://a[.=“未找到文本”] 根据,如果没有找到元素,但如何抑制;警告";使用Selenium::Remote::Driver?,selenium,perl,warnings,suppress-warnings,selenium-remotedriver,Selenium,Perl,Warnings,Suppress Warnings,Selenium Remotedriver,如何获取上述代码而不是以打印此警告: 执行命令时出错:无此类元素:无法定位 元素://a[.=“未找到文本”] 根据,如果没有找到元素,但没有警告,则函数会发出“警告”不会抑制它 如何抑制此“警告”使用find\u element而不是find\u element\u by\u xpath。前者抛出异常而不是发出警告。您可以使用以下包装器捕获这些异常: no warnings; use Selenium::Remote::Driver; my $driver = Selenium::Remo
没有警告,则函数会发出“警告”脚本中的代码>不会抑制它
如何抑制此“警告”使用find\u element
而不是find\u element\u by\u xpath
。前者抛出异常而不是发出警告。您可以使用以下包装器捕获这些异常:
no warnings;
use Selenium::Remote::Driver;
my $driver = Selenium::Remote::Driver->new;
$driver->get('https://www.crawler-test.com/');
$driver->find_element_by_xpath('//a[.="text not found"]');
nf
代表“非致命性”
为Selenium::Chrome编写,但也应与Selenium::Remote::Driver配合使用
根据,如果没有找到元素,但没有警告,则函数会发出“警告”脚本中的代码>不会抑制它
对。警告
杂注是词汇性的。将无警告添加到代码中只会影响代码。它不会关闭代码使用的其他模块中的警告。正如上面所说:
这个pragma的工作原理与“严格”pragma类似。这意味着警告杂注的范围仅限于封闭块。这还意味着pragma设置不会在文件之间泄漏(通过“使用”、“要求”或“执行”)。这允许作者独立定义将应用于其模块的警告检查的程度
find\u element\u by\u xpath
发出警告<代码>查找元素
将发出嘎嘎声。@CJ7已修复。
sub nf_find_element {
my $node;
if (!eval {
$node = $web_driver->find_element(@_);
return 1; # No exception.
}) {
return undef if $@ =~ /Unable to locate element|An element could not be located on the page using the given search parameters/;
die($@);
}
return $node;
}
sub nf_find_elements {
my $nodes;
if (!eval {
$nodes = $web_driver->find_elements(@_);
return 1; # No exception.
}) {
return undef if $@ =~ /Unable to locate element|An element could not be located on the page using the given search parameters/;
die($@);
}
return wantarray ? @$nodes : $nodes;
}
sub nf_find_child_element {
my $node;
if (!eval {
$node = $web_driver->find_child_element(@_);
return 1; # No exception.
}) {
return undef if $@ =~ /Unable to locate element|An element could not be located on the page using the given search parameters/;
die($@);
}
return $node;
}
sub nf_find_child_elements {
my $nodes;
if (!eval {
$nodes = $web_driver->find_child_elements(@_);
return 1; # No exception.
}) {
return undef if $@ =~ /Unable to locate element|An element could not be located on the page using the given search parameters/;
die($@);
}
return wantarray ? @$nodes : $nodes;
}