Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
find element...click() dont work
#1
Hello world,
I have the next function

  
f1="/html/body/div[2]/main/div....section[1]"
f2="/html/body/div[2]/main/div....section[2]"
f3="/html/body/div[2]/main/div....section[3]"...

f=[f1,f2,f3....]

b=0

try:
    driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
    d1=driver.find_element_by_xpath("/html/body/div[2]/..section[1]")
    b=b+1

    d2=driver.find_element_by_xpath("/html/body/div[2]/...section[2]")
    b=b+1

    d3=driver.find_element_by_xpath("/html/body/div[2]/...section[3]")
    b=b+1....

 
except NoSuchElementException as e:
	print("no more")

def my_function(i,driver):
	while i<b:
		driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
		import time
		time.sleep(2)
		element=driver.wait.until(EC.presence_of_element_located((By.XPATH,f[i])))
		driver.find_element_by_xpath(f[i]).click()
		try:
			import time
			time.sleep(1)
			print(" click again")
			driver.find_element_by_xpath(f[i])
			driver.find_element_by_xpath(f[i]).click()
		except NoSuchElementException as e:
			print("no need double click ")

		try: 
	    
			myDynamicElement = driver.find_element_by_xpath("/html/section[8]/...input")                                                  
		
			driver.find_element_by_xpath("/html/section[8]/...input").click()           
		
		except NoSuchElementException as e:
			driver.wait.until(EC.presence_of_element_located((By.XPATH,"/html/section[9]/..input")))
			
			driver.find_element_by_xpath("/html/section[9]/...input").click()
		import time
		time.sleep(2)
		driver.back()
		i=i+1



if b>0:
	my_function(0,driver) 
and it runs perfect, the problem inside the function I need to have the second
print(" click again")
driver.find_element_by_xpath(f[i])
driver.find_element_by_xpath(f[i]).click()

because sometimes the python find and click, but the page is not loading, so
i create this second step for make sure the button is clicked, and works, but sometimes this is not working and looks I have to create another same code find....click()
Do you know why it happens, have one solution.

thank you world
Reply


Messages In This Thread
find element...click() dont work - by windows11 - Apr-11-2020, 07:53 AM
RE: find element...click() dont work - by windows11 - Apr-16-2020, 08:42 AM
RE: find element...click() dont work - by Larz60+ - Apr-16-2020, 01:43 PM
RE: find element...click() dont work - by windows11 - Apr-17-2020, 09:30 AM
RE: find element...click() dont work - by law - Apr-18-2020, 01:36 PM
RE: find element...click() dont work - by windows11 - Apr-22-2020, 02:06 PM
RE: find element...click() dont work - by law - Apr-23-2020, 11:13 PM

Possibly Related Threads…
Thread Author Replies Views Last Post
  How to find element in a deeply nested html structure Orientation_group 5 1,629 Oct-09-2023, 10:13 AM
Last Post: Larz60+
  Selenium suddenly fails to find element Pavel_47 3 6,548 Sep-04-2022, 11:06 AM
Last Post: Pavel_47
  Seleniun does not work with a website element flote21 2 2,483 Jan-12-2021, 07:38 PM
Last Post: flote21
  Unable to click element in web page Kalpana 0 1,933 Jun-25-2020, 05:20 AM
Last Post: Kalpana
  Find element using xpath engli 3 4,071 May-20-2020, 08:56 AM
Last Post: Larz60+
  Find Dynamic Input Element Class Problem wazacko 0 1,668 Apr-03-2020, 11:46 AM
Last Post: wazacko
  bypassing find element click() windows11 1 1,978 Apr-02-2020, 11:55 AM
Last Post: Larz60+
  How find link element zinho 3 3,254 Mar-31-2020, 12:29 PM
Last Post: snippsat
  wait for element and click windows11 2 2,769 Mar-21-2020, 09:23 PM
Last Post: windows11
  How to find which frame/iframe my element belongs to? smaria 1 2,137 Nov-18-2019, 09:21 PM
Last Post: Larz60+

Forum Jump:

User Panel Messages

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