Tag Archives: selenium

Unknown error: cannot find chrome binary when running selenium under Linux

For Linux system, running Selnium script will report the following error

Traceback (most recent call last):
  File "./obp_pb_get_csv.py", line 73, in <module>
    browser = webdriver.Chrome('/usr/bin/chromium') # Get local session of chrome
  File "/usr/lib64/python2.7/site-packages/selenium/webdriver/chrome/webdriver.py", line 46, in __init__
    self.service.start()
  File "/usr/lib64/python2.7/site-packages/selenium/webdriver/chrome/service.py", line 64, in start
    raise WebDriverException("Can not connect to the ChromeDriver")
selenium.common.exceptions.WebDriverException: Message: 'Can not connect to the ChromeDriver'

Solution:

1. Confirm whether Chrome browser is installed, command: Chrome browser - version 0

2. If not, use the following command to install: sudo apt get install chromium browser

3. Get chromedriver and visit the following link http://chromedriver.storage.googleapis.com/index.html

4. Decompress Chromdriver.zip

5. Move the file to the path/usr/bin, command: sudo MV chromedriver/usr/bin

6. Switch to/usr/bin directory, command: CD/usr/bin

7. Make it executable, command: sudo Chmod a + X chromedriver

8. Perform the following code tests:

from selenium import webdriver

driver = webdriver.Chrome()
driver.get("http://www.google.com")
print driver.page_source.encode('utf-8')
driver.quit()
display.stop()

 

Python selenium — webriver cheat sheet

Recently, I saw a webriver cheat sheet on axatrikx, which is only made in Java. I thought I could organize a python version, and I got this blog post. The main methods and key points in webriver are sorted into a table for easy reference.

Webdriver Cheat Sheet

If it helps you, or if you have any good suggestions, please let me know.

Pdf version can be downloaded here


For more articles on Python selenium, please pay attention to my CSDN column: Python selenium automated test details

Python + selenium drop-down list error message: element not interactive

Today is going to make a whole page automation, wrote a drop-down list, run the script to throw the exception: selenium.com mon. Exceptions. ElementNotVisibleException: Message: element not interactable
As shown in the figure below, the script failed to run after using the select_by_index() method. It was found that the code ~~ was not carefully examined. The code was not select-option, but table.
The script is as follows:

driver.find_element_by_xpath("//*[@id=\"style_box\"]/div[1]").click()
#Select(s).select_by_index(3)
driver.find_element_by_xpath("//*[@id=\"style_box\"]/div[2]/div[1]/table/tbody/tr[2]").click()

Very simple two clicks, run after an error selenium.com mon. Exceptions. ElementNotVisibleException: Message: element not interactable
After debugging for several times, it was found that there was no waiting time added. Add time.sleep(3), debug again, and it was successful.
On the one hand, we must analyze the front-end code, on the other hand, when the foot is wrong, especially when it comes to switching, it is better to add a wait time to try ~~
 

 

RemoveError: ‘requests‘ is a dependency of conda and cannot be removed from conda‘s operating env

1. The question is:

removeError: ‘requests’ is a dependency of Conda and cannot be removed from Conda’s operating environment.
removeError: ‘setup_tools’ is a dependency of CONDA and cannot be removed from CONDA’s operating environment.
2. Solutions
Force Conda to be updated before installation

conda update --force conda

3. More related questions
https://github.com/conda/conda/issues/8149