Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
drive wait in try
#1
Hello guys Im trying to click in a button in one webpage, but this button can have two different Xpath
/html/body/div[2]/main/div[1]/div/div/div/div/div/div[3]/div/section[8]/div/div[1]/div/form/input
/html/body/div[2]/main/div[1]/div/div/div/div/div/div[3]/div/section[9]/div/div[1]/div/form/input

try: 
		
		print("page loading")                                                       
		driver.wait.until(EC.presence_of_element_located((By.XPATH,"/html/body/div[2]/main/div[1]/div/div/div/div/div/div[3]/div/section[8]/div/div[1]/div/form/input")))
		driver.find_element_by_xpath("/html/body/div[2]/main/div[1]/div/div/div/div/div/div[3]/div/section[8]/div/div[1]/div/form/input").click()           
		driver.wait.until(EC.presence_of_element_located((By.NAME,"username")))
		driver.find_element_by_name("username").send_keys("")
		driver.wait.until(EC.presence_of_element_located((By.NAME,"password")))
		driver.find_element_by_name("password").send_keys("")
		print("loging")
		driver.wait.until(EC.presence_of_element_located((By.XPATH,"/html/body/div[2]/div/div[1]/login/div/login-form/div[1]/form/input")))
		driver.find_element_by_xpath("/html/body/div[2]/div/div[1]/login/div/login-form/div[1]/form/input").click()           
		
		
		print("next")
		print("2 sec")
		import time 
		time.sleep(2)

		driver.back()
		print("going back e i=i+1")
		i=i+1
	except NoSuchElementException as e:                
		driver.wait.until(EC.presence_of_element_located((By.XPATH,"/html/body/div[2]/main/div[1]/div/div/div/div/div/div[3]/div/section[9]/div/div[1]/div/form/input")))
		driver.find_element_by_xpath("/html/body/div[2]/main/div[1]/div/div/div/div/div/div[3]/div/section[9]/div/div[1]/div/form/input").click()           
		
		driver.wait.until(EC.presence_of_element_located((By.NAME,"username")))
		#driver.find_element_by_name("username").send_keys("")
		driver.wait.until(EC.presence_of_element_located((By.NAME,"password")))
		driver.find_element_by_name("password").send_keys(")
		print("loging")
		driver.wait.until(EC.presence_of_element_located((By.XPATH,"/html/body/div[2]/div/div[1]/login/div/login-form/div[1]/form/input")))
		driver.find_element_by_xpath("/html/body/div[2]/div/div[1]/login/div/login-form/div[1]/form/input").click()           


		print("2 sec")
		import time 
		time.sleep(2)

		driver.back()
		
		i=i+1
		
the problem is when the button have the 2nd option, I have always a error in

driver.wait.until(EC.presence_of_element_located((By.XPATH,"/html/body/div[2]/main/div[1]/div/div/div/div/div/div[3]/div/section[8]/div/div[1]/div/form/input")))
because he can not find...

the code don't jump for the
except NoSuchElementException as e:
and keep working...

do you know if I have a way to choose: the first Xpath appear click
between :

Xpath
/html/body/div[2]/main/div[1]/div/div/div/div/div/div[3]/div/section[8]/div/div[1]/div/form/input
/html/body/div[2]/main/div[1]/div/div/div/div/div/div[3]/div/section[9]/div/div[1]/div/form/input
Reply


Possibly Related Threads…
Thread Author Replies Views Last Post
  Need Help with Selenium Explicit Wait gw1500se 6 2,853 Nov-28-2021, 09:44 PM
Last Post: Larz60+
  selenium wait for text question Larz60+ 3 2,501 Oct-25-2021, 09:50 AM
Last Post: Larz60+
  wait for element and click windows11 2 2,603 Mar-21-2020, 09:23 PM
Last Post: windows11
  wait.until(EC.element_to_be_clickable) failed to click gahhon 4 7,864 Feb-23-2019, 04:58 AM
Last Post: gahhon

Forum Jump:

User Panel Messages

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