请考虑以下代码:
from parsel import Selector
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
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.common.action_chains import ActionChains
driver = webdriver.Chrome('/usr/bin/chromedriver')
driver.get('https://www.bizbuysell.com/buy/')
btn = driver.find_element_by_xpath('//a[text()="Select Categories"]')
ActionChains(driver).move_to_element(btn).click(btn).perform()
WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, '//a[@class="toggleAll"]'))).click()
driver.find_element_by_xpath('//button[text()="Save Changes"]').click()
driver.quit()
单击"选择类别"href 链接时,弹出模式对话框(它不是 iframe(不会出现。我错在哪里?
尝试将按钮定义为:
btn=WebDriverWait(driver, 5).until(EC.element_to_be_clickable((By.XPATH, '//a[text()="Select Categories"]')))
编辑:查看启动驱动程序页面最大化是否有帮助。
options=webdriver.ChromeOptions()
options.add_argument('start-maximized')
driver = webdriver.Chrome(options=options)