from selenium.webdriver.common.action_chains import ActionChains
# 滑块验证
def slider(self):
retry_num = 0
while retry_num < 5:
try:
# 却换框架
self.driver.switch_to.default_content()
self.driver.switch_to.frame('alibaba-login-box')
try:
self.driver.switch_to.frame('baxia-dialog-content')
except:
print(f'无需验证, 登录中...')
self.fm_login_submit_click()
return None
# 当前滑块状态
nocaptcha = self.driver.find_element(By.ID, 'nocaptcha')
if nocaptcha.is_displayed():
if '请按住滑块,拖动到最右边' in nocaptcha.text.strip():
slide = self.driver.find_element(By.ID, 'nc_1_n1z')
action = ActionChains(self.driver)
action.click_and_hold(slide)
for x in [10, 20, 30, 40, 50, 40, 30, 20, 10, 0, 0, 0]:
action.move_by_offset(x, 0)
time.sleep(1 / 10)
action.release()
action.perform()
time.sleep(0.5)
nocaptcha = self.driver.find_element(By.ID, 'nocaptcha')
if nocaptcha.is_displayed():
if '验证失败,点击框体重试' in nocaptcha.text.strip():
print(f'滑块验证({retry_num+1})次: {nocaptcha.text.strip()}')
nocaptcha.click()
time.sleep(0.5)
nocaptcha = self.driver.find_element(By.ID, 'nocaptcha')
if not nocaptcha.is_displayed():
print(f'滑块验证({retry_num+1})次: 验证成功, 登录中...')
self.fm_login_submit_click()
return None
except BaseException as e:
print(f'滑块验证({retry_num+1})次: 验证失败, {e}')
retry_num += 1
一直出现验证失败,点击框体重试(error:7k86hb)。 这个知不知道怎么解决啊?