为了账号安全,请及时绑定邮箱和手机立即绑定

Selenium webdriver 不像浏览器那样解释标记,我不能像浏览器那样加载 DOM

Selenium webdriver 不像浏览器那样解释标记,我不能像浏览器那样加载 DOM

慕尼黑5688855 2022-12-15 15:21:46
我想使用 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


查看完整回答
反对 回复 2022-12-15
  • 1 回答
  • 0 关注
  • 55 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信