TimeOutException当使用link_text显式等待在selenium webdriver与python [英] TimeOutException when use link_text with explicit wait in selenium webdriver with python

查看:243
本文介绍了TimeOutException当使用link_text显式等待在selenium webdriver与python的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用带有python的selenium webdriver。我想根据他们指向的链接使用显式等待定位元素。为了实现这一点,我正在使用

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

这是html代码:

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

每次我运行这个查询,我得到 TimeOutException 但是如果我使用 By.ID ,我可以找到元素。我试图为其他 link_text 正常工作的网站也这样做。



如果我没有明确的等待使用,我可以找到元素,但有额外的修改,我得到 StaleException



我无法找到解决方案。请帮我解决这个问题。
提前感谢

解决方案

也许它不是使用PartialLinkText的正确标签?



通过部分链接文本查找元素


Selenium允许您识别超链接控制一个部分
文本。当动态生成文本时,这可能非常有用。
换句话说,一个网页上的文本可能会在您的
下次访问中不同。我们可能可以使用这些
动态生成的链接文本共享的公共文本来标识它们。 //将点击
取消链接


尝试使用LinkText


仅通过链接文本查找超链接文本。使用链接的文本是
可能是点击链接的最直接的方式,因为它是我们在
页面上看到的。



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.

解决方案

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.

这篇关于TimeOutException当使用link_text显式等待在selenium webdriver与python的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆