I'm writing code to login to the reddit website. I've written code to handle the notification when I first go on the reddit website then it clicks the login button. My issue is when I click the login button and I'm presented with the login page selenium is unable to find the username field to enter the username in. I've written login to switch to the iframe but it's still unable to find it.
public class Reddit {
public static void main(String[] args) {
System.setProperty("-");
Map<String, Object> prefs = new HashMap<String, Object>();
prefs.put("profile.default_content_setting_values.notifications", 2);
ChromeOptions options = new ChromeOptions();
options.setExperimentalOption("prefs", prefs);
WebDriver driver = new ChromeDriver(options);
driver.get("http://www.reddit.com");
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
driver.findElement(By.linkText("Log In")).click();
Issue is on the code below. Its unable to type in 'test'
driver.switchTo().frame(0);
driver.findElement(By.xpath("//input[@id='loginUsername']")).sendKeys("test");