0

I use this great solution for waiting until the page loads completely. But for one page it's don't work:

 from selenium import webdriver
 driver = webdriver.FireFox()
 driver.get("https://vodafone.taleo.net/careersection/2a/jobsearch.ftl")
 element = driver.find_element_by_xpath(".//*[@id='currentPageInfo']")
 print element.id, element.text
 driver.find_element_by_xpath(".//a[@id='next']").click()
 element = driver.find_element_by_xpath(".//*[@id='currentPageInfo']")
 print element.id, element.text

Output:

{52ce3a9f-0efb-49e1-be86-70446760e422} 1 - 25 of 1715
{52ce3a9f-0efb-49e1-be86-70446760e422} 26 - 50 of 1715

How to explain this behavior?

P.S.
With PhantomJS occurs the same thing
Selenium lib version 2.47.1
Edit
It's ajax calls on page. This solution is used in tasks similar to that described in this article

Community
  • 1
  • 1
El Ruso
  • 14,745
  • 4
  • 31
  • 54
  • you're linking a solution for waiting, but you do not use it in your code example? something missing? And where exactly is your code not working as expected? Because in your example the result looks pretty much as expected – drkthng Aug 13 '15 at 11:42
  • @drkthng element.id must changing when page reloaded for this solution, but it's stay same – El Ruso Aug 13 '15 at 13:26
  • why should the id change? it is an *ID*entifier for an element and should ideally stay the same -> but if you're sure, then you can post the related HTML code before and after the click (would be highly irregular though) – drkthng Aug 13 '15 at 13:30
  • @drkthng "...the solution relies on the fact that selenium records an (internal) id-number for all elements on a page... When a page refreshes or loads, it gets a new html element with a new ID" - citation from linked answer. – El Ruso Aug 13 '15 at 13:50
  • you're right -> see my answer, if you would provide some of the html, we could have a closer look – drkthng Aug 13 '15 at 14:30

1 Answers1

1

Without the HTML one can only guess:

Reading the linked answer, the behaviour you observe is most probably because clicking the "next" button is not loading the whole page again but is only making an ajax call or something and filling an already existing table with new values.

This means that the whole page stays "the same" and thus also the "current page info" element still has the same id (just some java-script that changed its text value)

To check this you can do the following:

write another test-method identical to the one you got, but this time you replace this line:

 driver.find_element_by_xpath(".//a[@id='next']").click()

with this line:

driver.navigate().refresh();

If it now gives you different ids, then I'm pretty sure, my guess is correct.

drkthng
  • 6,651
  • 7
  • 33
  • 53
  • Yes, it's ajax. But it's internal id's that must be change anyway. You can read this http://www.obeythetestinggoat.com/how-to-get-selenium-to-wait-for-page-load-after-a-click.html for understanding problem that must be solved (and this approach works ok in all situations except this site) – El Ruso Aug 13 '15 at 15:13
  • html - https://vodafone.taleo.net/careersection/2a/jobsearch.ftl I think "wall of HTML" not improve understanding issue – El Ruso Aug 13 '15 at 15:16
  • when you click on that next button, the whole page does NOT reload, just the content of the table with id "jobs" gets updated, the "jobPager" div where your next button resides stays as it is, and is not reloaded, thus you won't get a new id. I don't know why you think that "internal id's must change anyway"? Maybe you should update your question with an example where it works as you expect... – drkthng Aug 13 '15 at 20:35