如何使此Internet Explorer脚本适应Chrome

时间:2018-08-22 12:48:06

标签: powershell

我有这个脚本可以在Internet Explorer中打开某些网站,我也想在Chrome上使用它,但由于-ComObject而无法适应它

$navOpenInBackgroundTab = 0x1000;
$IE = New-Object -ComObject InternetExplorer.Application
$IE.navigate2("http://website.com");
$IE.navigate2("http://website.com", $navOpenInBackgroundTab);
$IE.navigate2("http://website.com", $navOpenInBackgroundTab);
$IE.navigate2("http://website.com", $navOpenInBackgroundTab);
$IE.navigate2("http://website.com", $navOpenInBackgroundTab);
$IE.navigate2("http://website.com", $navOpenInBackgroundTab);
$IE.navigate2("http://website.com", $navOpenInBackgroundTab);
$IE.navigate2("http://website.com", $navOpenInBackgroundTab);
$IE.navigate2("http://website.com", $navOpenInBackgroundTab);
$IE.navigate2("http://website.com", $navOpenInBackgroundTab);
$IE.navigate2("http://website.com", $navOpenInBackgroundTab);
$IE.navigate2("http://website.com", $navOpenInBackgroundTab);
$IE.navigate2("http://website.com", $navOpenInBackgroundTab);
$IE.navigate2("http://website.com", $navOpenInBackgroundTab);
$IE.navigate2("http://website.com", $navOpenInBackgroundTab);
$IE.navigate2("http://website.com", $navOpenInBackgroundTab);
$IE.navigate2("http://website.com", $navOpenInBackgroundTab);
$IE.Visible = $true 

谢谢您的时间

2 个答案:

答案 0 :(得分:1)

Start-Process "chrome.exe" "www.google.com"

您可以按名称启动进程,甚至可以像上面那样向其传递参数(URL)

答案 1 :(得分:0)

您可以使用硒并执行以下操作:

Add-Type -Path "C:\Automation\Selenium\Selenium.WebDriverBackedSelenium.dll"
Add-Type -Path "C:\Automation\Selenium\ThoughtWorks.Selenium.Core.dll"
Add-Type -Path "C:\Automation\Selenium\WebDriver.dll"
Add-Type -Path "C:\Automation\Selenium\WebDriver.Support.dll"

$driver = New-Object OpenQA.Selenium.Chrome.ChromeDriver
$driver.Navigate().GoToUrl("https://www.google.com/")
$driver.Navigate().GoToUrl("https://www.google.com/")
$driver.Navigate().GoToUrl("https://www.google.com/")

$driver.Quit();

要获取dll,您可以执行以下操作:

在桌面上,加载Visual Studio并添加以下Nuget程序包。

Selenium.WebDriverBackedSelenium
Selenium.WebDriver
Selenium.Support
Selenium.RC
Selenium.Chrome.WebDriver

转到nuget软件包文件夹,然后将以下dll和exe复制到名为C:\Automation\Selenium的文件夹中:

  • Selenium.WebDriverBackedSelenium.dll
  • ThoughtWorks.Selenium.Core.dll
  • WebDriver.dll
  • WebDriver.Support.dll
  • chromedriver.exe