サティヤムRastogi:
注:コードは、Chromeブラウザを開きますが、あまりにも上記のエラーが発生します。
from selenium import webdriver
main_url = 'https://www.linkedin.com' # URL A
tab_url = 'https://www.google.com' # URL B
chromedriver = 'C:\Program Files (x86)\Google\Chrome\Application\chrome.exe'
# Open main window with URL A
browser= webdriver.Chrome(chromedriver)
browser.get(main_url)
スクリプトを実行しようとすると、エラーの下に取得しています。
Error: Message: Service C:\Program Files (x86)\Google\Chrome\Application\chrome.exe unexpectedly exited. Status code was: 0
supputuri:
私はexecution_path変数を設定世話をしても、スクリプトを実行すると、自動的にドライバをダウンロードしますwebdriver_managerを使用して好むだろう。
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
main_url = 'https://www.linkedin.com' # URL A
tab_url = 'https://www.google.com' # URL B
# Open main window with URL A
browser= webdriver.Chrome(ChromeDriverManager().install())
browser.get(main_url)
あなたは2つの別々のタブで両方のURLを開くことを計画している場合は、以下を使用します。
from selenium import webdriver
from webdriver_manager.chrome import ChromeDriverManager
main_url = 'https://www.linkedin.com' # URL A
tab_url = 'https://www.google.com' # URL B
# Open main window with URL A
browser= webdriver.Chrome(ChromeDriverManager().install())
browser.get(main_url)
#print the current url
print(driver.current_url)
# open tab_url in new window
driver.execute_script("window.open(tab_url)")
# switch to the new window
driver.switch_to.window(driver.window_handles[1])
# check if the url is equals to tab_url
print(driver.current_url)
if driver.current_url == tab_url:
print(driver.current_url + " - Passed.")
driver.close()
# close the window
driver.close()