如果只有类名可用,如何通过selenium webdriver触发按钮单击



我正在使用selenium webdriver编写python来模拟按钮单击并选择复选框。然而,它失败了。请告知如何执行点击"再次搜索"按钮,然后选中"查询"复选框。然后按下"应用滤镜"按钮。
见下面的代码。

from selenium import webdriver
from selenium.webdriver.common.by import By
web = webdriver.Chrome()
url ="https://www.spareroom.co.uk/flatshare/search.pl"
web.get(url)
# page 1
web.find_element(By.ID, "search_by_location_field").clear()
web.find_element(By.ID, "search_by_location_field").send_keys("SW5")
web.find_element(By.ID,"onetrust-accept-btn-handler").click()
web.find_element(By.ID,"search-button").click()
# page 2
# to press the button "Search Again"
# to select the checkbox "Ensuite"
# to press the button "Apply filters"
url = 'https://www.spareroom.co.uk/flatshare/search.p'
wait = WebDriverWait(web, 20)
web.get(url)
wait.until(EC.element_to_be_clickable((By.ID, 'onetrust-accept-btn-handler'))).click()
wait.until(EC.element_to_be_clickable((By.CSS_SELECTOR, 'div.panel-tab > a:nth-child(2)'))).click()
web.find_element(By.ID, "search_by_location_field").clear()
web.find_element(By.ID, "search_by_location_field").send_keys("SW5")
web.find_element(By.ID,"search-button").click()

首先等待接受按钮弹出。单击高级选项卡,然后查找元素。

进口:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait 
from selenium.webdriver.support import expected_conditions as EC

相关内容

  • 没有找到相关文章

最新更新