Home > database >  Chrome with WebDriver--Why is it disappearing as soon as I hit "run"? Chrome Driver versio
Chrome with WebDriver--Why is it disappearing as soon as I hit "run"? Chrome Driver versio

Time:09-27

Running Selenium with Chrome Webdriver; my program worked for 4 months until Edge suddenly stopped working, switched to Chrome at behest of another [far more capable] scripter Now Chrome doesn't stay open and won't run my program! I literally ONLY changed which webdriver I use for this code; from Edge --> Chrome! It worked fine before

driver = webdriver.Chrome('C:\path..')
df = pd.read_excel('my_workbook...')
while variable_in_df <= X:
      driver.get(f'URL...')
      (((gets CSS element whatever)))
      return (CSS element from webpage)

The erros are:

Traceback (most recent call last):
    driver = launchBrowser()
    driver = webdriver.Chrome(executable_path=PATH);
    super(WebDriver, self).__init__(DesiredCapabilities.CHROME['browserName'], "goog",
    RemoteWebDriver.__init__(
    self.start_session(capabilities, browser_profile)
    response = self.execute(Command.NEW_SESSION, parameters)
    self.error_handler.check_response(response)

Another error says ChromeDriver is version 106 but wehnever I download Chrome it says it's 105. wghat??

CodePudding user response:

You need to match the driver to the version of the browser you are using. It may be that your script stopped working with MS Edge because your browser updated and the webdriver didn't match the newer version of the browser anymore. You will need to periodically update the webdriver to match the browser version.

In the case of Chrome not working, it again sounds like a driver version mismatch. It sounds like your browser is on version 105, but you have the 106 driver. I suggest checking the version of Chrome you have installed on your machine and downloading the matching driver from here:

https://chromedriver.chromium.org/downloads

Alternatively, you can switch back to Edge and get the matching driver here:

https://developer.microsoft.com/en-us/microsoft-edge/tools/webdriver/

You can check the version in most browsers under Help > About or similar from the main menu.

I hope this helps.

CodePudding user response:

To overcome this problem, use WebDriverManager: refer - https://bonigarcia.dev/webdrivermanager/ and https://github.com/bonigarcia/webdrivermanager.

To install: pip install webdriver-manager

Then, in the code, add the below lines:

For Chrome:

from selenium.webdriver.chrome.service import Service as ChromeService
from webdriver_manager.chrome import ChromeDriverManager

driver = webdriver.Chrome(service=ChromeService(ChromeDriverManager().install()))

For Edge:

from selenium.webdriver.edge.service import Service as EdgeService
from webdriver_manager.microsoft import EdgeChromiumDriverManager

driver = webdriver.Edge(service=EdgeService(EdgeChromiumDriverManager().install()))
  • Related