Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Selenium stale element reference
#2
I got it to work using xpath instead of link text. As my links were in one column in a table, i just had to change the row number in the xpath for each iteration. As xpath will remain constant even if the page is reloaded (this i am concluding because..), this code works.

	views = browser.find_elements_by_link_text('View')
	a = len(views) + 1
	views = browser.find_element_by_xpath('//form/div[3]/center/div[3]/table/tbody/tr[4]/td/div[1]/table/tbody/tr[' + str(a) + ']/td[4]/a')	
	while a > 1: #to exclude the header row
		window_before = browser.window_handles[0]
		views.click()
		browser.switch_to_window(window_before)
		a -= 1
		if a != 1:
			views = browser.find_element_by_xpath('//form/div[3]/center/div[3]/table/tbody/tr[4]/td/div[1]/table/tbody/tr[' + str(a) + ']/td[4]/a')
:)
Reply


Messages In This Thread
Selenium stale element reference - by test - Sep-19-2018, 07:09 PM
RE: Selenium stale element reference - by test - Sep-19-2018, 10:19 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Selenium suddenly fails to find element Pavel_47 3 6,346 Sep-04-2022, 11:06 AM
Last Post: Pavel_47
  Clicking on element not triggering event in Selenium Python (Event Key is not in data dkaeloredo 2 4,297 Feb-16-2020, 05:50 AM
Last Post: dkaeloredo
  stale element reference keuninkske 1 2,328 Jan-19-2020, 09:56 AM
Last Post: keuninkske
  Selenium locating an element. JokerTux 3 2,720 Dec-28-2019, 08:50 AM
Last Post: snippsat
  Selenium returning web element instead of desired text newbie_programmer 1 5,209 Dec-11-2019, 06:37 AM
Last Post: Malt
  Python Selenium getting table element trengan 2 8,589 Dec-31-2018, 03:02 PM
Last Post: trengan
  Click Element if displayed using Selenium and Python giaco__mar 1 3,549 Dec-27-2018, 06:19 PM
Last Post: metulburr
  Simple Element Check Code in Selenium Not Working digitalmatic7 1 3,019 Feb-18-2018, 06:53 AM
Last Post: metulburr
  Selenium - Googlemaps element not visible Barnettch3 3 5,664 Jan-15-2018, 08:07 PM
Last Post: Barnettch3
  locating element with selenium after login sumandas89 1 3,660 Jan-15-2018, 02:40 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020