0

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");
LBoyNewbie
  • 45
  • 1
  • 6
  • The login of reddit is displayed in an IFrame. This might help you save your problem: [Find elements inside forms and iframe using Java and Selenium WebDriver](https://stackoverflow.com/questions/24247490/find-elements-inside-forms-and-iframe-using-java-and-selenium-webdriver) – OH GOD SPIDERS Feb 22 '21 at 13:58
  • code is working perfectly fine for me as is – StrikerVillain Feb 22 '21 at 16:35

0 Answers0