Tag Archives: selenium

[Solved] AttributeError: module ‘selenium.webdriver‘ has no attribute ‘Chrome‘

**

Attributeerror: module ‘selenium. Webdriver’ has no attribute ‘chrome’

**
Description:
there is no problem creating a Google browser directly in the IDE
this error is reported when you go to Python
this is a novice problem

solution:
the reason for the error is that the selenium module is not installed in Python
this module is added in the setting project interpreter

in addition:
if it has been preceded, But not now
the possible reason is that you have opened a new project, which needs to be imported again

[Solved] Selenium error: staleelementreferenceexception exception

StaleElementReferenceException

Problem reporting and solution

Problem reporting error

# clcik to the next page
web.find_element_by_xpath('//*[@id="nexthehe"]').click()

the element is no longer attached to the DOM : the element is no longer attached to the dom

Solution:

The element is no longer attached to the dom

Analyze the cause

It is possible that elements that are no longer attached to the DOM tree are guided (for example, document. Documentelement)

But the page content is not loaded and cannot be found

resolvent:

Still, looking for the element again

try:
    # clcik to the next page
    web.find_element_by_xpath('//*[@id="nexthehe"]').click()
    # time.sleep(1)
except Exception:
    print('failed to next page')
    web.find_element_by_xpath('//*[@id="nexthehe"]').click()

The ADB server port is changed to 10001, and appium cannot connect to the device

After modifying the ADB server port to 10001, enter ADB devices – L in CMD to successfully detect the device:

Open appium and run the script. The appium running log shows that the device cannot be connected and has been killing the port number 5037 ADB server. The error information is as follows:

I changed the port number of the ADB server to 10001. Why do I still kill 5037?

Seeing this error, when I first thought about it, the environment variable of the modified port was not configured to appium. Click the edit configurations button of appium, and I found that there were no new buttons, but only the default environment variable:

I searched a lot of information on the Internet and found no solution. Finally, I found a solution in an appium Chinese user guide,   Put the guide link here: appium Chinese User Guide – Jianshu (Jianshu. Com)

Modify the running script and add ‘adbport’: ‘10001’ to desired_ In caps Dictionary:

Restart appium, run the script again, connect the device successfully, and solve the problem!

PS: when using appium, you can familiarize yourself with the above instructions and have a general understanding of appium; Then, when running, you should pay attention to the running log. Many problems can be located step by step through the error reporting of the log

Ubuntu Server: How to Install Chrome

Install Google without interface

1. Install chrome on the command line of Ubuntu server version

sudo apt-get install libxss1 libappindicator1 libindicator7
wget https://dl.google.com/linux/direct/google-chrome-stable_current_amd64.deb
sudo dpkg -i google-chrome*.deb # Might show "errors", fixed by next line
sudo apt-get install -f
google-chrome --version # check the version

2. Drivers of different browsers

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

Firefox:https://github.com/mozilla/geckodriver/releases

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

Safari:https://webkit.org/blog/6900/webdriver-support-in-safari-10/

3. Test whether the installation is successful

from selenium import webdriver
 
chrome_options = webdriver.ChromeOptions()
chrome_options.add_argument('--headless')
chrome_options.add_argument('--disable-gpu')
chrome_options.add_argument('--no-sandbox')
client = webdriver.Chrome(chrome_options=chrome_options, executable_path='your path')   
client.get("https://www.baidu.com")
print (client.page_source.encode('utf-8'))
client.quit()

4. Error in running selenium, permission denied. Add executable permissions to driver files

command: sudo chmod +x chromedriver

This version of chromedriver only supports chrome version 92 crawler simulates the problem of Google plug-in version when the browser clicks and reports an error

When the crawler simulates the browser’s click, an error is reported in the version of the Google plug-in. In this case, the driver of the Google browser stored locally is incorrect and needs to be updated. The specific solutions are as follows:

resolvent:

Open the following website and download the corresponding version of chromedriver. If you can’t find the exact version number, just find 91

http://chromedriver.storage.googleapis.com/index.html

Be sure to download the driver according to your browser version

My version number is 91.0.4472.124, so I should download the driver corresponding to this version number. The website of download driver is the one above     http://chromedriver.storage.googleapis.com/index.html

After clicking in, the interface is as follows

Then find the corresponding version file, download it, unzip it, and copy and paste it into the

In the program error report, you need to delete or cover the previous version in the path where you installed Google before

Leave this new version of the driver. In addition to that, I need to make a copy to the IDE environment where you are running. I use the code written in Python language here, so I need to make a copy of the driver file to the local installation path of Python

At last, it ran successfully

[Solved] Selenium python send_key error: list object has no attribute

Learning selenium positioning element, the teacher wrote send_ Key (), but I didn’t click in this method. I kept prompting
selenium Python send_ Key error: list object has no attribute
therefore, both methods can be used to solve the problem.
PS: [0] I don’t know what it means. I’ll come back to understand it when I’m in-depth learning

driver = webdriver.Chrome()
driver.get("https://www.baidu.com")
userID = driver.find_elements(By.ID,"kw")[0]
userID.send_keys("123")
driver = webdriver.Chrome()
driver.get("https://www.baidu.com")
driver.find_element(By.ID,"kw").send_keys("456")

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