【发布时间】:2016-01-16 13:11:50
【问题描述】:
我在 python 中使用 selenium webdriver。我想根据它们指向的链接使用显式等待定位元素。为了实现这一点,我正在使用
element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.PARTIAL_LINK_TEXT, 'dashboard')))
这是相应的 html 代码:
<li class="headerLink" name="dashboard"><a href="http://www.xy.com/dashboard" class="touch">Dashboard</a></li>
每次我运行这个查询时,我都会得到TimeOutException,但如果我使用By.ID,我就能找到元素。我尝试对 link_text 工作正常的其他网站做同样的事情。
如果我在没有明确等待的情况下使用,我可以找到元素,但经过额外修改,我会得到StaleException。
我无法找到解决方案。这个你能帮我吗。 提前致谢。
【问题讨论】:
-
能贴出相关的html吗?
-
but if I use By.ID, I am able to locate element- 您提供的元素没有 ID。另外,您是否在页面上看到任何 iframe 元素? -
我已经尝试将
id用于其他标签。不,它没有 iframe。无论如何,我每次搜索时都在使用 default_context()。 -
我也让它使用 xpath 工作。我仍然不知道为什么 partial_link_text 和 link_text 不起作用,但使用 xpath,selenium 似乎找到了元素。
标签: python selenium selenium-webdriver exception-handling