Unable to locate element and TimeoutException when WebDriverWait is used

北慕城南 提交于 2019-12-02 13:03:31

Your yDmH0d, fcxH9b, etc. seems to be dynamically generated and change each time you load/reload the page. The only thing which doesn't change is span tag text.

So I would recommend using the following simple selector:

WebDriverWait(driver, 15).until(EC.presence_of_element_located((By.XPATH, "//span[text()='Show more']"))).click()

Also consider using Page Object Model design pattern, it will make your life easier when it comes to test support when/where UI changes and lets you write tests much faster.

See Page Objects page of Selenium Python documentation for more information if needed.

As the element is JavaScript enabled element so to click() it you need to induce WebDriverWait for the element_to_be_clickable() and you can use the following Locator Strategy:

  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//div[@role='button']//span/span[text()='Show more']"))).click()
    
  • Note : You have to add the following imports :

    from selenium.webdriver.support.ui import WebDriverWait
    from selenium.webdriver.common.by import By
    from selenium.webdriver.support import expected_conditions as EC
    
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!