我无法识别“使用Apple ID登录”元素(在iclod.com页面)。
这是我现在正在使用的:WebElement用户名= driver.findElement(By.xpath(“ // [@ id = \” account_name_text_field \“]”));username.sendKeys(“ [email protected]”);
[此外,我尝试使用Chropath和Ranorex创建的CSS,但仍无法正常工作。我做错了吗?
请检查以下解决方案。 iframe与您的网页相关联,与Web元素输入框进行交互之前,您需要切换到iframe。
driver = webdriver.Chrome(executable_path=r" path of chromedriver.exe")
driver.maximize_window()
wait = WebDriverWait(driver, 10)
driver.get("https://www.icloud.com")
wait.until(EC.presence_of_element_located((By.ID, "auth-frame")))
driver.switch_to.frame("auth-frame")
inputBox = wait.until(EC.element_to_be_clickable((By.ID, "account_name_text_field")))
inputBox.send_keys("your test")
# switch back to main window
driver.switch_to.default_content()
输出:
该元素在iframe
内部,您需要首先进行切换。
您可以使用.frameToBeAvailableAndSwitchToIt
:
driver.get("https://www.icloud.com/");
new WebDriverWait(driver, 20).until(ExpectedConditions.frameToBeAvailableAndSwitchToIt(By.id("auth-frame")));
WebElement username = new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.id("account_name_text_field")));
username.sendKeys("[email protected]");
添加WebDriverWait
,网络加载时间很长。