Tag Archives: selenium

[Solved] ssl_client_socket_impl.cc handshake failed (Same Codes in Different Environments)

First of all, the same script environment (the same code, the same plug-in version) has no problem running on my native environment, windoiws11.

However! Report an error ssl_client_socket_impl.cc  handshake failed~ QaQ in the newly installed Windows 10 environment.

[19852:2032:0912/202419:ERROR:ssl_client_socket_impl.cc(983)] handshake failed;
 returned -1, SSL error code 1, net_error -100

I have added these two conditions, but the loop still reports an error and the script stops directly

options.add_argument('--ignore-certificate-errors')
options.add_argument('--ignore-ssl-errors')

There is no difference between the chromedriver version and the Chrome version.

I can’t find any other reason

Python+Selenium Error: AttributeError: ‘WebDriver‘ NameError: name ‘By‘ is not defined

python 3.10.1

selenium 4.4.3

Old version Package:

from selenium import webdriver

New version Package:

from selenium import webdriver
from selenium.webdriver.common.by import By

You need to import one more, otherwise the ‘By’ will report an error

Positioning statement

drive.find_element(By.NAME,"username").send_keys("astudy")

[Solved] selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn

1. Phenomenon: Jenkins cannot call out the browser page when building selenium, and Jenkins reports an error when building selenium: selenium.common.exceptions WebDriverException: Message: unknown error: DevToolsActivePort file doesn’t exist

2. Troubleshooting: run the project code directly under the Jenkins working directory, call out the browser normally, and the use case execution is completed

3. Reason: after Jenkins is built, the default node for running automation cases is the master, and the processes running on the master are background processes, so you can’t see the browser running interface

4. Solution:

① build the project in a graph free way
② add a slave node to Jenkins and point the project construction node to slave

[Solved] selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn

Error Messages: selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn’t exist

Traceback (most recent call last):
  File "/opt/Vcert/myVcert/vul.py", line 2, in <module>
    from selenium import webdriver
ImportError: No module named selenium
Traceback (most recent call last):
  File "/opt/Vcert/myVcert/vul.py", line 228, in <module>
    main()
  File "/opt/Vcert/myVcert/vul.py", line 44, in main
    browser = my_browser()
  File "/opt/Vcert/myVcert/vul.py", line 31, in my_browser
    browser = webdriver.Chrome(executable_path='/opt/bin/chromedriver', chrome_options=chrome_options)
  File "/opt/py3/lib64/python3.6/site-packages/selenium/webdriver/chrome/webdriver.py", line 81, in __init__
    desired_capabilities=desired_capabilities)
  File "/opt/py3/lib64/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 157, in __init__
    self.start_session(capabilities, browser_profile)
  File "/opt/py3/lib64/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 252, in start_session
    response = self.execute(Command.NEW_SESSION, parameters)
  File "/opt/py3/lib64/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
    self.error_handler.check_response(response)
  File "/opt/py3/lib64/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
    raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: DevToolsActivePort file doesn't exist

 

Solution:
1. Kill chromedriver, kill webdriver, kill chrome.
2. Add browser.close() after each browser.

[Solved] Python-selenium locates an element cannot be clicked error: ElementClickInterceptedException

Problem Description:

prompt: elementclickinterceptedexception: Message: element click
when performing selenium UI automation test, you may encounter the situation that elements can be located but cannot be clicked. The following error is:

When writing an automatic program, you will encounter a new window pop-up, and the program always locates the element on the first window page by default. In this way, the element will not be located, and the program will report an error.

For example, when locating an element, the UI is covered by the pop-up window in the list. If an element cannot be located, the program reports an error
click the code of the located element:

web_driver.find_element(By.CSS_SELECTOR,'#funtype_click').click()

Cause analysis:

prompt: elementclickinterceptedexception
when locating an element, the UI is covered by the pop-up window in the list. If an element cannot be located, the element click has been blocked</ font>


Solution:

Error code:

# Click on the function category
web_driver.find_element(By.CSS_SELECTOR,'#funtype_click').click()

Resolved Code:

# Functional Category
funtype_click = web_driver.find_element(By.CSS_SELECTOR,'#funtype_click')
web_driver.execute_script('arguments[0].click()',funtype_click)

AttributeError: ‘WebDriver‘ object has no attribute ‘w3c‘

Problems encountered in the process of automatic testing of mobile terminal with Python + appnium.

Reason: I reported an error in selenium 3.3.1. After uninstalling selenium, I reinstalled selenium 4.0.0 (installed by default and the latest version). I ran it again and the problem was solved. Only the positioning mode needs to be changed to the latest, otherwise there will be a warning.

The new positioning method of mobile terminal is as follows:

from appium.webdriver.common.mobileby import MobileBy

driver.find_element(MobileBy.ID, "com.tencent.mm:id/hej").click()

[Solved] Selenium Error: ERROR: Message: element not interactable

For this error, you can check whether there are duplicate elements on the next page

For example, the following: run the error on the old newspaper and find that there are duplicate elements on the page

password=(By.XPATH,'//input[@placeholder="Please input the password"])'

Solution: find the one you need, as follows

password=(By.XPATH,'(//input[@placeholder="Please input the password"])[2]')

Specify element positioning method: (//span [text() = ‘match’) [2]

Solution of selenium driven edge error reporting

Solution of selenium driven edge error reporting

Selenium uses edge to run an error message: ‘microsoftwebdriver. Exe’ executable needs to be in path

// An highlighted block
selenium.common.exceptions.WebDriverException: Message: 'MicrosoftWebDriver.exe' executable needs to be in PATH

Problem cause: the driver file name written in selenium is inconsistent with the actual driver file name

Solution: rename the downloaded driver file msedgedriver.exe to Microsoft webdriver.exe, save it and run it again

Error reporting using selenium in pycharm

The error information is as follows:

  That is, for the chrome driver to execute, it must be added to the environment variable

Download the chrome driver that is consistent with the version of Google browser on your computer, and unzip the chrome driver into the scripts folder of Python

[Python] Right-click Selenium to Save the picture error: attributeerror: solution to module ‘pyscreen’ has no attribute ‘locationonwindow’

When crawling pictures with selenium module, simulate right clicking and select “save picture as” to save the picture (pyautogui module is not used)

from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.keys import Keys
from selenium import webdriver
from time import sleep

url = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fcdn.duitang.com%2Fuploads%2Fitem%2F201202%2F18%2F20120218194349_ZHW5V.thumb.700_0.jpg&refer=http%3A%2F%2Fcdn.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633348528&t=794e58b55dfe37e5f3082568feb89783'

driver = webdriver.Chrome()
driver.get(url)
element = driver.find_element_by_xpath('/html/body/img[1]')  

action = ActionChains(driver)  
action.move_to_element(element)  
action.context_click(element)  
action.send_keys(Keys.ARROW_DOWN)  
action.send_keys('v')  

action.perform()  
sleep(2)

driver.quit()  

When you execute the above code, you will find that you do not click the keyboard after right clicking, because the page is not controlled by selenium after right clicking. At this point, we need to use the pyautogui module, which is a module for automatically controlling the mouse and keyboard
you need to PIP download the wheel first

pip install pyautogui

Modified code:

from selenium.webdriver.common.action_chains import ActionChains
from selenium import webdriver
from time import sleep
import pyautogui

url = 'https://gimg2.baidu.com/image_search/src=http%3A%2F%2Fcdn.duitang.com%2Fuploads%2Fitem%2F201202%2F18%2F20120218194349_ZHW5V.thumb.700_0.jpg&refer=http%3A%2F%2Fcdn.duitang.com&app=2002&size=f9999,10000&q=a80&n=0&g=0n&fmt=jpeg?sec=1633348528&t=794e58b55dfe37e5f3082568feb89783'

driver = webdriver.Chrome()
driver.get(url)
element = driver.find_element_by_xpath('/html/body/img[1]') 

action = ActionChains(driver) 
action.move_to_element(element) 
action.context_click(element) 
action.perform() 

pyautogui.typewrite(['v']) 
sleep(1) 
pyautogui.typewrite(['1', '.', 'j', 'p', 'g'])
pyautogui.typewrite(['enter'])

sleep(1)

driver.quit() 

The red explosion will be found after execution:

attributeerror: module ‘pyscreen’ has no attribute ‘locateonwindow’

It is actually very simple to solve this problem
we directly download the highest version 0.9.53 after PIP install pyautogui
we only need to download version 0.9.50, so this problem will not exist

pip install pyautogui==0.9.50

Just execute the code again~