selecting element in python selenium

后端 未结 4 999
遇见更好的自我
遇见更好的自我 2021-01-23 21:27

I\'m trying to log onto a webpage with python selenium. I\'ve found an element and it is enabled, but when I try to send_keys() to it I get an error. The main thing (I think)

相关标签:
4条回答
  • 2021-01-23 21:30

    I know that this problem is solved , I got stuck in similar problem and same error
    I have fixed it by just make my script sleep for 2 seconds then resume it was just Connection speed problem

    ...
    time.sleep(2)
    ...
    

    don't forget to import time module

    import time
    

    wish that help anyone in future :D

    0 讨论(0)
  • 2021-01-23 21:37

    You can use explicit waits:

    from selenium.webdriver.common.by import By
    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.support import expected_conditions as EC
    
    element = WebDriverWait(driver, 10).until(
        EC.presence_of_element_located((By.CLASSNAME, "inputUsername"))
    )
    
    ...
    
    0 讨论(0)
  • 2021-01-23 21:49

    To make the username field to be visible, you need to move cursor to the login link:

    ....
    
    driver.get('http://www.etoro.com/au')
    action = webdriver.ActionChains(driver)
    action.move_to_element(driver.find_element_by_xpath(
        './/a[@class="top-link"]/span[text()="Login"]'
    ))
    action.perform()
    # TODO Need to wait until the `inputUsername` field is visible
    elem = driver.find_element_by_class_name('inputUsername')
    ...
    
    0 讨论(0)
  • 2021-01-23 21:56

    I had similar issue, selenium was not able to focus and open the login modal. Instead it was focusing on the next element. This was the locator I was using:

    elem = browser.find_element_by_xpath("//nav[2]/ul/li[3]/a").click()
    

    I just changed [3] with [2] and it was able to locate the element and open the modal:

    elem = browser.find_element_by_xpath("//nav[2]/ul/li[2]/a").click()
    
    0 讨论(0)
提交回复
热议问题