Bertrand
Bertrand

Reputation: 361

Selenium webdriver doesn't interpret the markup as a browser does, I can't load all HTML elements in the DOM as a browser does

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

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());
}

Upvotes: 0

Views: 152

Answers (1)

RKelley
RKelley

Reputation: 1119

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

Upvotes: 3

Related Questions