1

I have a relatively simple question. I am trying to get a button to be clicked on a popup window that I believe is javascript with Selenium. I ran the Selenium add on for Firefox and it gave me code, but it doesn't work. The code is fairly long and all works just fine, but when it gets to this line:

driver.find_element_by_id("cancelExistingReservationButton").click()

It just waits and then it errors out with this message:

That button is on the screen, but it never gets clicked. I know that the part of the code works that follows it, but I just can't get it to do anything with that line.

    Traceback (most recent call last):
  File "C:/Users/Bradley/Desktop/testParkFare.py", line 34, in test_park_fare
    driver.find_element_by_id("cancelExistingReservationButton").click()
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 65, in click
    self._execute(Command.CLICK_ELEMENT)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py", line 385, in _execute
    return self._parent.execute(command, params)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 171, in execute
    response = self.command_executor.execute(driver_command, params)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 349, in execute
    return self._request(command_info[0], url, body=data)
  File "C:\Python27\lib\site-packages\selenium\webdriver\remote\remote_connection.py", line 380, in _request
    resp = self._conn.getresponse()
  File "C:\Python27\lib\httplib.py", line 1074, in getresponse
    response.begin()
  File "C:\Python27\lib\httplib.py", line 415, in begin
    version, status, reason = self._read_status()
  File "C:\Python27\lib\httplib.py", line 379, in _read_status
    raise BadStatusLine(line)
    BadStatusLine: ''

Any help you could give would be really appreciated.

Here is the entirety of the code:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import Select
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC


from selenium.common.exceptions import NoSuchElementException
from selenium.common.exceptions import NoAlertPresentException
import unittest, time, re

class Test2(unittest.TestCase):
    def setUp(self):
        self.driver = webdriver.Firefox()
        self.driver.maximize_window()
        self.driver.implicitly_wait(60)
        self.base_url = "https://disneyworld.disney.go.com"
        self.verificationErrors = []
        self.accept_next_alert = True

    def test_2(self):
        driver = self.driver
        driver.get(self.base_url + "/dining/grand-floridian-resort-and-spa/1900-park-fare/")
        driver.find_element_by_xpath("(//button[@type='button'])[2]").click()
        driver.find_element_by_link_text('27').click()
        driver.find_element_by_css_selector("div.select-toggle.hoverable").click()
        driver.find_element_by_id('diningAvailabilityForm-searchTime-0').click()
        driver.find_element_by_css_selector("#partySize-wrapper > div.select-toggle.hoverable").click()
        driver.find_element_by_id("partySize-3").click()
        driver.find_element_by_css_selector("span.buttonText").click()
        availabletimes = driver.find_element_by_xpath('//*[@id="timesContainer"]/div[2]').get_attribute("innerHTML")

        availableTimesList = []

        startpoint = availabletimes.find("buttonText")+12
        endpoint = availabletimes.find("span", startpoint)-2

        allwantedtimes = ['8:45 AM', '8:40 AM', '8:50 AM', '8:55 AM', '8:35 AM', '8:30 AM', '8:25 AM', '8:20 AM',
                          '9:00 AM', '9:05 AM', '9:15 AM', '9:20 AM']

        positions = ["//div[@id='timesContainer']/div[2]/a/span/span/span",
                     "//div[@id='timesContainer']/div[2]/a[2]/span/span/span",
                     "//div[@id='timesContainer']/div[2]/a[3]/span/span/span"]

        while startpoint > 500:
            availableTimesList.append(availabletimes[startpoint: endpoint])
            startpoint = availabletimes.find("buttonText", endpoint)+12
            endpoint = availabletimes.find("span", startpoint)-2


        if len(availableTimesList) < 4:
            for y in range(0, len(allwantedtimes)):
                if allwantedtimes[y] in availableTimesList:
                    driver.find_element_by_xpath(positions[availableTimesList.index(allwantedtimes[y])]).click()
                    driver.find_element_by_id("loginPageUsername").clear()
                    driver.find_element_by_id("loginPageUsername").send_keys("ourlogin")
                    driver.find_element_by_id("loginPagePassword").clear()
                    driver.find_element_by_id("loginPagePassword").send_keys("ourpassword")
                    driver.find_element_by_id("loginPageSubmitButton").click()
                    print('We got here at least')
                    element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "cancelExistingReservationButton")))
                    element.click()
                    print('But never here')
                    driver.find_element_by_id("cancelExistingReservationButton").click()
                    driver.find_element_by_id("continueWithExistingReservationButton").click()
                    driver.find_element_by_css_selector("#guestSelectBox0-wrapper > div.select-toggle.hoverable").click()
                    driver.find_element_by_css_selector("#guestSelectBox0-2 > span.rawOption").click()
                    driver.find_element_by_css_selector("#guestSelectBox1-wrapper > div.select-toggle.hoverable").click()
                    driver.find_element_by_css_selector("#guestSelectBox1-3 > span.rawOption").click()
                    driver.find_element_by_css_selector("#guestSelectBox2-wrapper > div.select-toggle.hoverable").click()
                    driver.find_element_by_css_selector("#guestSelectBox2-4 > span.rawOption").click()
                    driver.find_element_by_id("done").click()
                    driver.find_element_by_id("done").click()
                    driver.find_element_by_id("mobilePhone").clear()
                    driver.find_element_by_id("mobilePhone").send_keys("8659473353")
                    driver.find_element_by_id("nextButton").click()
                    driver.find_element_by_css_selector("span.rich-checkbox.unselected").click()
                    driver.find_element_by_id("nextButton").click()
                    break







    def is_element_present(self, how, what):
        try: self.driver.find_element(by=how, value=what)
        except NoSuchElementException, e: return False
        return True

    def is_alert_present(self):
        try: self.driver.switch_to_alert()
        except NoAlertPresentException, e: return False
        return True

    def close_alert_and_get_its_text(self):
        try:
            alert = self.driver.switch_to_alert()
            alert_text = alert.text
            if self.accept_next_alert:
                alert.accept()
            else:
                alert.dismiss()
            return alert_text
        finally: self.accept_next_alert = True

    def tearDown(self):
        self.driver.quit()
        self.assertEqual([], self.verificationErrors)

if __name__ == "__main__":
    unittest.main()
6
  • What happens if you manually click the button in the browser? Also, could you share a link to the web-site and provide the complete code you have so far? Thanks. Commented Jan 20, 2015 at 1:25
  • If I click the button manually, all works as expected. Here is a link to the website:disneyworld.disney.go.com/dining/grand-floridian-resort-and-spa/… Commented Jan 20, 2015 at 12:23
  • I also added the full code to the original post. Commented Jan 20, 2015 at 12:30
  • I don't see the button with id="cancelExistingReservationButton" on the page that appears after the login. Also, why are you making the login so late? why don't login right at the beginning of the test? Thanks. Commented Jan 20, 2015 at 13:01
  • The way the page works is that you search for an available time for a reservation and if there is one at a time you want you click on a small oval bubble that appears below the search box. At this point, it asks you to log in to confirm your reservation. It is at that point that another box appears and says that you already have another reservation with an hour of this reservation and would you like to cancel that reservation and make this one. That is the box I am having trouble with. If you look at my other comment on user2565883's post, I have pictures of what it looks like. Commented Jan 20, 2015 at 13:28

2 Answers 2

1

Let's change the logic here. First - log in, then open up the page and try making a reservation. Also, instead of presence_of_element_located you should use visibility_of_element_located expected condition:

# log in
driver.get(self.base_url + '/login/')
driver.find_element_by_id('loginPageUsername').send_keys('ourlogin')
driver.find_element_by_id('loginPagePassword').send_keys('ourpassword')
driver.find_element_by_id('loginPageSubmitButton').click()

driver.get(self.base_url + "/dining/grand-floridian-resort-and-spa/1900-park-fare/")
driver.find_element_by_xpath("(//button[@type='button'])[2]").click()
driver.find_element_by_link_text('27').click()

...

if len(availableTimesList) < 4:
    for y in range(0, len(allwantedtimes)):
        if allwantedtimes[y] in availableTimesList:
            driver.find_element_by_xpath(positions[availableTimesList.index(allwantedtimes[y])]).click()
            print('We got here at least')
            element = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.ID, "cancelExistingReservationButton")))
            element.click()
            print('But never here')
Sign up to request clarification or add additional context in comments.

1 Comment

That worked so well! It seemed that the visibility change was the key. I appreciate it so much.
1
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

element = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.ID, "cancelExistingReservationButton")))

element.click()

You could try this to make sure the button is loaded and ready to be clicked by Selenium.

1 Comment

I tried that, but unfortunately, it was pretty much the same result. Here is a link to what the website looks like before: dropbox.com/s/hjf8b5n2p79kbow/Before.jpg?dl=0 and here is what it looks like when the offending button is on the screen: dropbox.com/s/lfgvhlgphznsdf4/Popup%20After.jpg?dl=0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.