1 回答
TA贡献1825条经验 获得超4个赞
带有创建帐户文本的链接位于 中,<iframe>
因此您必须:
诱导WebDriverWait以等待所需的框架可用并切换到它。
您可以使用以下定位器策略:
LINK_TEXT
:
driver.get("https://www.shopdisney.com/merch-pass/product-selection/arendelle-castle-collection-from-frozen")
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.ID,"disneyid-iframe")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "Create an Account"))).click()
使用CSS_SELECTOR:
driver.get("https://www.shopdisney.com/merch-pass/product-selection/arendelle-castle-collection-from-frozen")
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.CSS_SELECTOR,"iframe[name='disneyid-iframe']")))
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "a.btn.btn-secondary.ng-isolate-scope"))).click()
使用XPATH:
driver.get("https://www.shopdisney.com/merch-pass/product-selection/arendelle-castle-collection-from-frozen")
WebDriverWait(driver,10).until(EC.frame_to_be_available_and_switch_to_it((By.XPATH,"//iframe[@name='disneyid-iframe']")))
WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.XPATH, "//a[text()='Create an Account']"))).click()
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
浏览器快照:
添加回答
举报