0

I am using Selenium to simulate login with Chrome browser. The login page has Slider button which needs to be dragged to complete the login process. The weird thing is that if I open the web page using driver.get(page). Then sliding verification code will always fail even I manually enter the username, pwd and drag the slider.

I tried to add user-agent but no help. Is there any other way? I understand that we can add user-data to skip this part but I just want to figure it out first.

The slider verification code will display if you try to log in more than once. It seems that the web page just detect you are using the script to log in. The error will be like:" ops, failed to verify. Please refresh again". Then I use driver.find_element_by_xpath("//*[@id='nocaptcha']/div/span/a").click() to refresh the slider.

Thanks in advance.

driver = webdriver.Chrome()
driver.get("https://login.taobao.com/member/login.jhtml?spm=a21bo.2017.754894437.1.5af911d95pqPfs&f=top&redirectURL=https%3A%2F%2Fwww.taobao.com%2F")
action = ActionChains(driver)
login()

def login():
    driver.find_element_by_class_name("login-switch").click()
    driver.find_element_by_id('TPL_username_1').clear()
    driver.find_element_by_id('TPL_username_1').send_keys('xxx')
    driver.find_element_by_id('TPL_password_1').clear()
    driver.find_element_by_id('TPL_password_1').send_keys("xxx")
    time.sleep(1.5)
    # driver.find_element_by_id('J_SubmitStatic').click()
    Slider()

def Slider():
    #Sliding verification code
    while True:
        try:
            slip=driver.find_element_by_xpath("//*[@id='nc_1_n1z']")
            action.click_and_hold(slip).perform()
            action.move_by_offset(150,0)
            time.sleep(0.8)
            action.move_by_offset(148,0)
            action.release().perform()
            time.sleep(2)
            text = driver.find_element_by_xpath("//*[@id='nc_1__scale_text']/span")
            if text.text.startswith("请在下方"):
                print("Successful")
                break
            if text.text.startswith("请点击"):
                print("Successful")
                break
            if text.text.startswith("请按住"):
                print("Failed. Try again")
                continue
        except Exception:
            ##Error occurs, click the "Refresh" button to refresh the sliding verification code again
            driver.find_element_by_xpath("//*[@id='nocaptcha']/div/span/a").click()
    driver.find_element_by_id('J_SubmitStatic').click()
Winnie-c
  • 179
  • 2
  • 13
  • I do not see any code pertaining to any tries to manipulate any things on the site? Where is your code that does not work? – Patrick Artner Oct 05 '18 at 11:02
  • Put your driver on hold with [WebDriverWait](https://stackoverflow.com/questions/26566799/wait-until-page-is-loaded-with-selenium-webdriver-for-python) until you complete this sort of verification manually. – fabio.avigo Oct 05 '18 at 11:05
  • if you are are testing on behalf of the site's developer ask them to implement test keys to stop the capture triggering: https://developers.google.com/recaptcha/docs/faq – dank8 Oct 05 '18 at 13:50
  • Update the question with your _code trials_ and _relevant error_ you are seeing – undetected Selenium Oct 05 '18 at 14:14
  • Edited the question. Thanks guys. – Winnie-c Oct 06 '18 at 10:15

0 Answers0