1

Recently, I'm using Selenium to simulate login a website (https://passport.zhaopin.com/org/login). During this simulate login, I have to click at a certain position according to the coordinate so that I can pass the captcha. However, I get confused with a bug raised by selenium for a whole day. My code is shown as below:

from selenium import webdriver
import time

driver =webdriver.Firefox(executable_path="/Users/mountain/geckodriver")
url = "https://passport.zhaopin.com/org/login"
driver.get(url)
time.sleep(4)

img_element = driver.find_element_by_class_name("captcha-container")

actions = webdriver.common.action_chains.ActionChains(driver)
actions.move_to_element_with_offset(img_element, 50, 50).click().perform()

Then, an error happens.enter image description here

I can't understand why 50 isn't an integer.

1 Answers1

1
actions.move_to_element_with_offset(img_element, 50, 50).click().perform()

click() is an in-place function, in-place functions behaves as follows:

In [1]: before=[3,4,5]
In [2]: after=before.append(6)
In [3]: type(after)
Out[3]: NoneType
In [4]: len(before)
Out[4]: 4
In [5]: before
Out[5]: [3, 4, 5, 6]

instead you should use:

action = actions.move_to_element_with_offset(img_element, 50, 50)
action.click()
action.perform()

here you can find complete explaination: How are Python in-place operator functions different than the standard operator functions?

Community
  • 1
  • 1
internety
  • 364
  • 3
  • 8