【发布时间】:2022-01-12 05:56:49
【问题描述】:
我正在尝试使用 Selenium 编写 Python 脚本,以查看是否可以自动执行我创建的示例事件的注册过程。这是活动页面:https://www.tickettailor.com/events/testing4/621753
我可以访问该页面并点击“加入客人名单”按钮:
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()
之后,我需要从 Category1 票的下拉菜单中选择“1”,让 Category2 中的票数保持为 0。之后,我需要输入姓名和电子邮件来确认我的订单。
但是,我根本找不到选择下拉菜单的元素。我试过driver.find_element_by_id,name,xpath,class_name,css_selector,但都没有奏效。我也尝试过使用 select 选项,如下所示:
select = Select(driver.find_element_by_id("quantity_2335182"))(quantity_2335182 是 Chrome 中检查元素中选择标签的 id),然后是 select.select_by_value('1')。它不断给出错误,例如:
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)
如果我不必像“quantity_2335182”那样指定特定的 id 并且可以根据通用类名、标签或 css_selector 选择下拉列表,我会更喜欢。另外,我只想选择两个下拉菜单中的第一个(仅编辑 Category1 而不是 Category2)。
【问题讨论】:
标签: python html selenium selenium-webdriver selenium-chromedriver