在Selenium和Perl中使用现有的Firefox会话

3

我已经有一个包含登录信息的Firefox会话,可以访问感兴趣的网站。现在我想使用Selenium和Perl进行操作。

我正在使用以下代码:

my $driver = Selenium::Remote::Driver->new;
$driver->get("http://www.google.com");
$driver->find_element('q','name')->send_keys("Hello WebDriver!");
print $driver->get_title() . "\n";

但是这段代码会打开一个新的空白 Firefox 会话。如何使用我已经设置好的 cookie 的现有会话呢?

2个回答

1
您想指定使用Firefox配置文件。
在Java中,代码应该是这样的...
ProfilesIni profile = new ProfilesIni();
FirefoxProfile firefoxProfile = profile.getProfile("Default"); // might need to switch this around depending on what it actually is named.
WebDriver driver = new FirefoxDriver(firefoxProfile);

(感谢此答案提供伪代码)


不幸的是,Perl绑定没有ProfilesIni类,也没有它的类似物。 - John Smith

0

我认为你可以尝试使用Perl驱动程序中的这个选项。

my $handles = $driver->get_window_handles;
   $driver->switch_to_window($handles->[1]);
   $driver->close;
   $driver->switch_to_window($handles->[0]);

我没有使用过它,但也许它会对你有所帮助!

如需更多信息,请参考此网站。 https://metacpan.org/pod/Selenium::Remote::Driver


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接