Python + selenium + web solution for automatic login cracking sliding verification code

1. Problem description

I recently wrote a case of automatic login, there is a process to crack the sliding verification code, but when locating the element on the sliding verification code, I always prompt that the corresponding element cannot be located, and the error is as follows:

Unable to locate element: {"method":"xpath","selector":"//div[@class='show-code']/input"}

When I first opened, I thought that the positioning method was wrong. I tried xpath positioning and id / name positioning, but it still reported an error; I later thought it was caused by a network delay problem, so I added a delay time.sleep () before positioning.

But after trying it, no matter how long the home is delayed, there is still a problem; the biggest reason for the next thought may be that the page does not jump to the verification code pop-up page, and then carefully read the next page code and found the verification code pop-up A frame, and another page is actually embedded in the frame, and the webdriver can only be recognized on one page at a time, so you need to first locate the corresponding frame to locate the elements on that page. This problem also made me have a headache for a long time, and finally solved it, happy.

 
Second, the solution
 
When locating the element above the verification code pop-up box, first jump to the frame frame, the specific code is as follows:
 
Note: If the network speed is not fast enough, it is better to add a delay time.
 
# Jump to iframe first
time.sleep(2)
driver.switch_to_frame('tcaptcha_iframe')
# Position the element that needs to slide
time.sleep(1)
source = driver.find_element_by_xpath("//div[@id='tcaptcha_drag_thumb']")
 

 

 

Guess you like

Origin www.cnblogs.com/lxmtx/p/12725550.html