-1

I have a school project where I want to sign into Google Drive with Selenium-Java and the code to use the "Enter Email or Phone" Box always says it cannot find that element. I have tried every single method of findElement. Css-selector, ID, Linktext, Name, xPath. All of them lead to "NoSuchElementException".

import org.openqa.selenium.By;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.WebDriver;
import java.util.Scanner;

public class finalProject {
    static WebDriver driver;
    static Scanner s = new Scanner(System.in);
    public static void launchBrowser() {

        // looking through my PC and running the chrome webdriver .exe file

        System.setProperty("webdriver.chrome.driver", "C:\\Users\\Lupus\\Downloads\\chromedrivernew\\chromedriver.exe");
        driver = new ChromeDriver();
        driver.get("http://drive.google.com"); // opening google drive's site
    }
    public static void signIn() {
        driver.findElement(By.linkText("Go to Drive")).click(); // clicking the "go to drive" button

        System.out.print("Email: ");
        String email = s.nextLine();
        System.out.print("Password: ");
        String pass = s.nextLine();

        WebElement email_field = driver.findElement(By.id("identifierId"));
        email_field.sendKeys(email);
    }
    public static void main(String[] args) {
        launchBrowser();
        System.out.println("Welcome to Google Drive! First, log into your Google Account.");
        signIn();

    }
}

1 Answers1

1

This solves your problem. Recommend you take a look.

The element isn't visible so due to an permanent overlay.

Replace first line in signIn() method with:

WebElement ele = driver.findElement(
//                By.xpath("//*[@id=\"start\"]/section[4]/div/div/div/a[3]")
                By.linkText("Go to Google Drive") // Both ^ works. Use one.
        );
        JavascriptExecutor executor = (JavascriptExecutor)driver;
        executor.executeScript("arguments[0].click();", ele);
Tony
  • 436
  • 1
  • 9
  • 17