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 的现有会话?

4

2 回答 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);

(感谢这个伪代码的答案)

于 2013-11-07T15:31:00.427 回答
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

于 2014-12-01T02:32:46.800 回答