Bottom Page

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
Quote

Top Page

Possibly Related Threads...
Thread Author Replies Views Last Post
  wait for element and click windows11 2 217 Mar-21-2020, 09:23 PM
Last Post: windows11
  wait.until(EC.element_to_be_clickable) failed to click gahhon 4 1,753 Feb-23-2019, 04:58 AM
Last Post: gahhon

Forum Jump:


Users browsing this thread: 1 Guest(s)