[Tutor] FW: Python Selenium
I am working with a site that allows you to make reservations for different times of the day. The HTML (controlled by someone else) does not include specific names for each time – the HTML is very similar. With help from this group, I have figured out how to locate an element using an xpath with the time spelled out (this way the module can substitute a time based on user input). Here is the line of code (for 7:35): br.find_element_by_xpath("//div[contains(.,'7:35')]") Here is where I need assistance: I need to access an element associated with that element to see if it is blank or occupied. I have included the HTML for two different time slots. The first (7:30) is not occupied as shown by the 4 class statements at the bottom with the ><. The second, for 7:35 is partially occupied – the names are shown as is the slot count information. I am trying to figure out a clever way to look down in the HTML once I have found the element to see if it is partially occupied or not. Any help with that would be appreciated. ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] click() performs unreliably
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 ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor
[Tutor] Python Imported Code
Introduction: I have written a 'program' that does some reasonable screen scraping off of a specific website. The program has gotten too large so I have tried to segment it into logical pieces (tkinter logic as a start) but I am having problems. Specifically I need to pass several dictionaries to the module (imported code) that validates some user selection and into the code that navigates through the website. I have also created a variable that is set to 0 when a valid entry has been made by the user (telling the scraper what to do) that needs to be checked in the scraper module that is waiting patiently before it starts. There are multiple threads working as well because I may need to run several session as once. After struggling with my basic need - the ability to pass variables/dictionaries across modules, especially imported modules, I have read everything I can find and tried small, demo programs. But is till can't get it What I need: An ability to create dictionaries (that have validation information in them) and variables (that signal status and contain information entered by the user in tinkter) that I can make available to all components. I have tried using global, but that fails. I also can't seem to use arguments because the module that tkinter fires up with this command: self.process_button = tk.Button(master, text='Process Request', \ font = ('times', regular_font, 'bold'),\ fg = "blue", command=self.Process_Reservation_Request) does not seem to support the presence of arguments. Demo Program - This currently bombs in part 3 - it can't seem to see the value/space created in part1. Any help or reference that will clearly show me how to solve this problem would be most appreciated. I have read a number of points that recommend against using global anywhere (it does not seem to work with imported code) but I just can't find a recommendation for doing something that seems pretty fundamental. Thanks to an and all that try to help! Part 1 import nice import nice2 global myGlobal myGlobal = "initial value" print(myGlobal) nice.changeGlobal() print (nice.myGlobal) nice2.changeGlobal() print("nice version = ", nice.myGlobal) print("nice2 version = ", nice2.myGlobal) print("mainline=", myGlobal) part 2 - stored as nice.py def changeGlobal(): global myGlobal #print("entering changeGlobal part 1", myGlobal) myGlobal = "hello" print("top of myGlobal", myGlobal) myGlobal="bye" print("changeGlobal =", myGlobal) #changeGlobal() Part3 stored as nice2 myGlobal = "hello" def changeGlobal(): global myGlobal print("first value = ", nice.myGlobal) myGlobal="it worked" print("in changeGlobal2 =", myGlobal) #changeGlobal() ___ Tutor maillist - Tutor@python.org To unsubscribe or change subscription options: https://mail.python.org/mailman/listinfo/tutor