Reputation: 1
I am trying to write a Python script with Selenium to see if I can automate the registration process for a sample event I created. Here is the event page: https://www.tickettailor.com/events/testing4/621753
I am able to access the page and click on "Join the guestlist" button:
from selenium import webdriver
driver = webdriver.Chrome('path_to_chromedriver')
driver.get('https://www.tickettailor.com/events/testing4/621753')
button = driver.find_element_by_link_text('Join the guestlist')
button.click()
After this, I need to select '1' from the dropdown menu of Category1 ticket and let # of tickets in Category2 remain as 0. Afterward, I need to enter the name and email to confirm my order.
However, I am not able to find the element to select the dropdown menu at all. I have tried driver.find_element_by_id,name,xpath,class_name,css_selector
, but none of them have worked. I have also tried it with the select option as in:
select = Select(driver.find_element_by_id("quantity_2335182"))
(quantity_2335182 is the id of the select tag in the inspect element in Chrome) and then select.select_by_value('1')
. It keeps giving errors such as:
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":"[id="quantity_2335182"]"}
(Session info: chrome=96.0.4664.93)
I would prefer if I don't have to specify the specific id as in "quantity_2335182" and can select the dropdown based on a general class name, tag, or css_selector. Also, I only want to select the first of the two dropdown menus (Only editing Category1 and not Category2).
Upvotes: 0
Views: 261
Reputation: 9969
wait=WebDriverWait(driver, 60)
driver.get('https://www.tickettailor.com/events/testing4/621753')
wait.until(EC.element_to_be_clickable((By.LINK_TEXT,"Join the guestlist"))).click()
wait.until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe#overlay_window")))
row1=Select(wait.until(EC.presence_of_element_located((By.XPATH,"(//select)[1]"))))
row1.select_by_index(1)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#submit"))).click()
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#name"))).send_keys("a")
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#email"))).send_keys("a")
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#email_confirm"))).send_keys("a")
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#submit"))).click()
## do captcha
key=wait.until(EC.presence_of_element_located((By.CSS_SELECTOR,".h-captcha"))).get_attribute("data-sitekey")
print(key)
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#submit"))).click()
Imports:
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.webdriver.support.select import Select
To automate this just click the link text, switch to the iframe overlay window , use the select import and select by index and then click the next button.
Upvotes: 1
Reputation: 5396
You are unable to interact with the dropdown because that popup is within Iframe. So First you have to switch to iframe and then you can interact with elements.
Here, Please see it's within iframe:
Your code steps would be :
driver.switch_to_frame("overlay_window")
driver.switch_to.default_content()
Upvotes: 0