0

I am learning Selenium Webdriver. I was trying to login "Quora" through Google. but in the email typing section, the code is not working. I am not able to figure out what is the problem. Please help. Below is my code:

import org.openqa.*;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

public class Demo2 {

    public static void main(String[] args) { 

        System.setProperty("webdriver.chrome.driver", "C:\\chromedriver.exe");

        WebDriver driver=new ChromeDriver();

        String url="https://quora.com";

        driver.get(url);

        WebElement ele1=driver.findElement(By.className("google_button_text"));

        ele1.click();       

        WebElement email1=driver.findElement(By.name("identifier"));

        email1.sendKeys("fggffgfd"); 

        WebElement next1=driver.findElement(By.className("RveJvd snByac")); 

        next1.click();

        WebElement password=driver.findElement(By.className("whsOnd zHQkBf"));

        password.click();

        password.sendKeys("Sffgdffdf3");

        WebElement next2=driver.findElement(By.className("RveJvd snByac")); 

        next2.click();          
    }
}
Nick
  • 4,820
  • 18
  • 31
  • 47
Saranya V
  • 1
  • 4

1 Answers1

0

Select the element using Id instead of Name. You can use

By.id("identifierId")

Instead of

By.name("identifier")

Try using WindowHandle like the below code snap:

ele1.click();

String mainWindowHandler = driver.getWindowHandle();

for(String winHandle : driver.getWindowHandles()){
    driver.switchTo().window(winHandle);
}

WebElement email1=driver.findElement(By.id("identifierId"));

It will write the text in Email field. Then you need to capture exact selector for Next button like By.cssSelector("#identifierNext > content > span"). In this way, try to find out the cssSelector for Password field and Next button as well.

At the end of code, you need add the below line of code to close the 2nd window and switch to the main window:

driver.close();
driver.switchTo().window(mainWindowHandler);

Hopefully, it resolves your issue.

Ali Azam
  • 2,047
  • 1
  • 16
  • 25