TimeOutException when use link_text with explicit wait in selenium webdriver with python

99封情书 提交于 2019-12-12 10:19:11

问题


I am using selenium webdriver with python. I want to use explicit wait for locating element on the basis of the links they are pointing to. For achieving this, I am using

element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, 'dashboard')))

Here is the html code for that:

<li class="headerLink" name="dashboard"><a href="http://www.xy.com/dashboard" class="touch">Dashboard</a></li>

Everytime I run this query, I get TimeOutException but if I use By.ID, I am able to locate element. I tried to do the same for other websites for which link_text worked fine.

If I use without explicit wait, I am able to find elements but with extra modification, I am getting StaleException.

I am unable to find the solution for this. Please help me out with this. Thanks in advance.


回答1:


Maybe its not the proper tag for using PartialLinkText ?

Find element by Partial Link Text

Selenium allows you to identify a hyperlink control with a partial text. This can be quite useful when the text is dynamically generated. In other words, the text on one web page might be different on your next visit. We might be able to use the common text shared by these dynamically generated link texts to identify them. // will click the "Cancel" link

Try to use LinkText

Find element by Link Text For Hyperlinks only. Using a link’s text is probably the most direct way to click a link, as it is what we see on the page.



来源:https://stackoverflow.com/questions/34827365/timeoutexception-when-use-link-text-with-explicit-wait-in-selenium-webdriver-wit

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