0

I would like to automate the authentication process in https://appleid.apple.com/ using java webdriver selenium, but html elements of the form doesn't loaded in the DOM

to my knowledge, Selenium webdriver interpret the markup as a browser does. And It apply the CSS styles, run the JavaScript and the dynamically rendered content be added to the DOM

  • Why HTML elements are not loaded in the DOM ?

  • How can I proceed, to fix it and load all elements in the DOM, exactly like a browser ?

N.B : https://appleid.apple.com/ website use Mustache.JS (logic-less template)

 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());
}
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
Bertrand
  • 341
  • 1
  • 2
  • 12
  • Does trying to find the element using a different type of selector such as the class selector using the value `form-textbox-text` return the element? That would help narrowing the issue down. I would also recommend stepping through the code using the debugging functionality of your IDE. – Matt Stannett May 27 '19 at 06:25

1 Answers1

3

The element you are trying to find is inside an iFrame. You will need to switch to this iFrame first and then proceed with finding the element as you already have.

driver.switchTo().frame("aid-auth-widget-iFrame");

WebElement inputName = driver.findElement(By.id("account_name_text_field"));

You can find some additional information about switching to iFrames here: https://www.guru99.com/handling-iframes-selenium.html

RKelley
  • 1,099
  • 8
  • 14