Powershell打开并循环浏览Firefox窗口和选项卡

时间:2018-12-13 11:52:01

标签: powershell

经过几个小时的谷歌搜索和游戏后,我宣布放弃并要求您提供智慧。

我想要的是一个脚本,

  • 打开2个Firefox窗口,每个窗口都有一些指向特定网页的标签
  • 将窗口移动并最大化到特定位置/屏幕
  • 每X秒循环两个窗口的标签

我无法在此计算机上安装其他软件,因此Firefox插件不是解决方案。但是,我可以使用Powershell,至少是它在Windows 7上开箱即用的方式。由于不熟悉Powershell,并且来自Perl开发背景,所以我使用伪代码的方法是:

my $first_process = start_process( "/path/to/firefox.exe -new-window http://url1 -new-tab http://url2" );
my $second_process = start_process( "/path/to/firefox.exe -new-window http://url3 -new-tab http://url4" );
my $first_window  = $first_process.get_window_handle();
my $second_window = $second_process.get_window_handle();

$first_window.move( $x1, $y1, $width, $height );
$second_window.move( $x2, $y2, $width, $height );

$shell = New-Object -ComObject wscript.shell
$first_window.give_focus();
sleep 2;
$shell.SendKeys('{F11}');
$second_window.give_focus();
sleep 2;
$shell.SendKeys('{F11}');

while(1)
{
  sleep 30;
  $first_window.give_focus();
  sleep 2;
  $shell.SendKeys('^{TAB}');
  sleep 30;
  $second_window.give_focus();
  sleep 2;
  $shell.SendKeys('^{TAB}');
}

我确定这是一个相当普遍的用例,我天真地希望能够很快找到如何做这件事的方法,但是我无法用谷歌找到一个解决方案,甚至我可以提出的一些解决方案通过反复试验使自己在一起。

注意:我不能使用IE,它必须是Firefox。

0 个答案:

没有答案