带破折号的属性名称不适用于 get_attribute (perl Selenium)
attribute names with dashes don't work with get_attribute (perl Selenium)
use feature 'say';
$selen = Selenium::Remote::Driver->new;
$selen->get("http://www.google.com");
$elem = $selen->find_element('(//div[@data-responsive-height-resize])[1]');
say $elem->get_attribute('data-responsive-height-resize'); # this doesn't work
say $selen->execute_script('return arguments[0].getAttribute("data-responsive-height-resize")', $elem); # this works
Selenium::Remote::WebElement::get_attribute
是否存在无法处理属性名称中的破折号的问题?还是我做错了什么?
添加评论作为答案。
在 documentation for get_attribute
中它说你可以使用布尔值作为第二个参数
If you want to get the initial condition (e.g. the values in the tag hardcoded in HTML), pass 1 as the second argument.
所以如果你尝试这样做,你可能会得到你想要的。 (而且它似乎确实有效)
use feature 'say';
$selen = Selenium::Remote::Driver->new;
$selen->get("http://www.google.com");
$elem = $selen->find_element('(//div[@data-responsive-height-resize])[1]');
say $elem->get_attribute('data-responsive-height-resize'); # this doesn't work
say $selen->execute_script('return arguments[0].getAttribute("data-responsive-height-resize")', $elem); # this works
Selenium::Remote::WebElement::get_attribute
是否存在无法处理属性名称中的破折号的问题?还是我做错了什么?
添加评论作为答案。
在 documentation for get_attribute
中它说你可以使用布尔值作为第二个参数
If you want to get the initial condition (e.g. the values in the tag hardcoded in HTML), pass 1 as the second argument.
所以如果你尝试这样做,你可能会得到你想要的。 (而且它似乎确实有效)