我想使用 java webdriver selenium 在https://appleid.apple.com/中自动执行身份验证过程,但表单的 html 元素未加载到 DOM 中据我所知,Selenium webdriver 像浏览器一样解释标记。它应用 CSS 样式,运行 JavaScript 并将动态呈现的内容添加到 DOM为什么 HTML 元素没有加载到 DOM 中?我该如何继续,修复它并加载 DOM 中的所有元素,就像浏览器一样?注意:https ://appleid.apple.com/网站使用 Mustache.JS(无逻辑模板) public static void main(String[] args) { System.setProperty("webdriver.chrome.driver", "chromedriver.exe"); ChromeOptions options = new ChromeOptions(); options.addArguments("--headless", "--disable-gpu", "--window-size=1920,1200", "--ignore-certificate-errors"); WebDriver driver = new ChromeDriver(options); driver.get("https://appleid.apple.com/"); waitForPageLoadComplete(driver, 30); //can't found input name element WebElement inputName = driver.findElement(By.id("account_name_text_field")); System.out.println(driver.getPageSource());}
1 回答
慕斯709654
TA贡献1840条经验 获得超5个赞
您要查找的元素位于 iFrame 中。您需要先切换到此 iFrame,然后继续查找已有的元素。
driver.switchTo().frame("aid-auth-widget-iFrame");
WebElement inputName = driver.findElement(By.id("account_name_text_field"));
您可以在此处找到有关切换到 iFrame 的一些其他信息: https ://www.guru99.com/handling-iframes-selenium.html
添加回答
举报
0/150
提交
取消