Problem with python library - Selenium

Asked

Viewed 740 times

-1

Hi, I’m looking to learn a little more about WEB interactions with some languages. The language I’m focusing on is Python (I already have some knowledge). I am using the Selenium library - webdriver and I just want to make a script of mine click on a button of a respective site.

from selenium import webdriver

browser = webdriver.Chrome()
browser.get('https://outlook.live.com/owa/')
browser.maximize_window()

btn = browser.find_element_by_xpath('/html/body/header/div/aside/div/nav/ul/li[2]/a')
btn.click()
browser.quit()

This simple code is giving these problems.

C:\pythonDocuments\venv\Scripts\python.exe C:/pythonDocuments/main.py
Traceback (most recent call last):
  File "C:\pythonDocuments\venv\lib\site-packages\selenium\webdriver\common\service.py", line 72, in start
    self.process = subprocess.Popen(cmd, env=self.env,
  File "C:\Users\ffccs\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 854, in __init__
    self._execute_child(args, executable, preexec_fn, close_fds,
  File "C:\Users\ffccs\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 1307, in _execute_child
    hp, ht, pid, tid = _winapi.CreateProcess(executable, args,
FileNotFoundError: [WinError 2] O sistema não pode encontrar o arquivo especificado

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "C:/pythonDocuments/main.py", line 3, in <module>
    browser = webdriver.Chrome()
  File "C:\pythonDocuments\venv\lib\site-packages\selenium\webdriver\chrome\webdriver.py", line 73, in __init__
    self.service.start()
  File "C:\pythonDocuments\venv\lib\site-packages\selenium\webdriver\common\service.py", line 81, in start
    raise WebDriverException(
selenium.common.exceptions.WebDriverException: Message: 'chromedriver' executable needs to be in PATH. Please see https://sites.google.com/a/chromium.org/chromedriver/home


Process finished with exit code 1

Unfortunately it was not bad installation of the library, I already installed manually and installed the pycharm to do the installation for it too and nothing went right. Thanks in advance!

3 answers

0

You can try downloading Chromedriver from the same version of your browser again.

To see: three points => help => on google Chrome

https://sites.google.com/a/chromium.org/chromedriver/downloads

So you have several options:

  • add it to the PATH of your system.

  • put it in the same directory as your Python script.

  • specify the location directly via executable path:

    driver = webdriver.Chrome(executable_path=r'C:/caminho/para/chromedriver.exe')

0

To use lib Selenium either in python or java require a web driver, firefox,Chrome or any browser has to download the driver corresponding to the desired browser.

But if your PC browser is outdated, file an error on the console, indicating that your browser did not follow the downloaded driver version.

Both your use browser and Chrome must be updated with the downloaded driver.After downloading you must indicate the path where your web driver is.

If you want to automate using Chrome, your browser and the web driver have to be the same version.

0

I believe you managed to solve with the tips of the colleagues above. Looking at your code, you need to get an improvement on this Locator. The xpath as it is, it can easily generate error if you have any changes in the element path. A hint is to use the id element. If the id not available, you can use the xpath thus:

seu_locator = (By.XPATH, "//h1[contains(@class, 'title2')])"

Browser other questions tagged

You are not signed in. Login or sign up in order to post.