[Tutor] click() performs unreliably

stephen.m.smith at comcast.net stephen.m.smith at comcast.net
Mon Nov 26 05:21:40 EST 2018


I am trying to click on one of two buttons on a page. Here is an image of
the relevant portion of the page, the HTML and the two xpaths.

 

 



 

 



 

/html/body/div[3]/div/div[3]/div[6]/div/div[2]/div/div[3]/a[1]

/html/body/div[3]/div/div[3]/div[6]/div/div[2]/div/div[3]/a[2]

 

I have made numerous attempts to click on the first button with very limited
success - it works maybe 25% of the time. Looking through the code snippet
below, you will be able to see some of the various techniques I have tried -
I commented out some of the attempts when they failed so that I could
remember what I have tried. I have looked extensively online at previous
posts, but can't find anything that works reliably. The code executes fine
and I can see the button depressed and get routed to the previous page, but
the other actions associated with the click (backing out the previous step)
are not performed. Yet if I pause the code and intervene by clicking on the
button by hand, the routing takes place and the associated steps are
executed. When I click on the second button (with a virtually identical
xpath address) the processing works as it should. 

 

I have tried to find the element by xpath and class name, I have tried
commands with a click() at the end of the find, I have tried
.send_keys("\n") at the end of the find and other approaches as well.  A
simple find_element_by_xpath with the address for the second button works
100% of the time. I really don't understand what I am missing and can't seem
to find another method to try. Thanks for any and all thoughts.

 

##            br.get('chrome://settings/')

##
br.execute_script('chrome.settingsPrivate.setDefaultZoom(1.5);')

 
br.find_element_by_xpath("/html/body/div[3]/div/div[3]/div[6]/div/div[2]/div
/div[3]/a[1]").click()

            #br.find_element_by_class_name("go_back_button").send_keys("\n")

    #   Back out time (test mode)

            #print(thread, "Test mode - backing out time(s)")

            #result = xpath_search(self, xpath_for_go_back_button, br, 10,
do_click)

##

##            button =
br.find_element_by_xpath("//*[@id='main']/div[6]/div/div[2]/div/div[3]/a[1]"
)

##            button.click()

##            #sleep(20)

##            result =
xpath_search(self,"/html/body/div[3]/div/div[3]/div[6]/div/div[2]/div/div[3]
/a[1]", br, 5, do_click) 

##            print("Back out time result =", result)

##            if result == failure:

##                self.queue.put("(" + thread + ") Unable to back out time")

##                if thread == "1":

##                    endApplication(self, br, thread)

####                return

##            try:

##                WebDriverWait(br,
5).until(EC.element_to_be_clickable((By.XPATH, xpath_for_go_back_button)))

##                back_out =
br.find_element_by_xpath(xpath_for_go_back_button)

##                back_out.click()

##                print("Cancel tee time worked")

##            except NoSuchElementException:

##                print("Cancel tee time did not work")

##                return

 

 

 



More information about the Tutor mailing list