0

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.

proprius
  • 502
  • 9
  • 20
  • 2
    Can you post the relevant html? – Guy Jan 16 '16 at 15:07
  • `but if I use By.ID, I am able to locate element` - the element you provided does not have an ID. Also, do you see any iframe elements on the page? – alecxe Jan 18 '16 at 11:16
  • I have tried using `id` for some other tag. No, it doesnt have iframe. Anyhow I am using default_context() everytime I search. – proprius Jan 18 '16 at 12:02
  • I also made it to work using xpath. I still dont know why partial_link_text and link_text are not working but with xpath, selenium seem to find the element. – proprius Jan 18 '16 at 12:03

1 Answers1

0

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.

Leon Barkan
  • 2,676
  • 2
  • 19
  • 43