Selenium webdriver code gets stuck

Discussion in 'Other Courses & Certifications' started by Anjani Kumar_4, Sep 16, 2017.

  1. Anjani Kumar_4

    Joined:
    Aug 21, 2017
    Messages:
    3
    Likes Received:
    0
    I am trying to automate the following steps :
    Step 1. Go to Google.com
    Step 2. Search for gmail
    Step 3. Click on Gmail
    Step 4. Verify you are on gmail site
    Step 5. Enter username
    Step 6. Click on next
    Step 7. Enter password
    Step 8. Click on Sign In
    Step 9. Verify you get a new page
    Step 10.Click on Compose button

    But the code gets stuck on the email field. The cursor keeps blinking on the email field.

    Here is the code :

    package com.google.mail;

    import org.openqa.selenium.By;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.ie.InternetExplorerDriver;

    public class OpenGmail {

    public static void main(String[] args) {

    WebDriver driver = new InternetExplorerDriver();
    System.setProperty("webdriver.ie.driver", "C:\\Users\\Chandra\\Desktop\\SELENIUM\\IEDriver\\IEDriverServer.exe");
    driver.get("www.google.com");
    driver.findElement(By.xpath("//*[@id='gbw']/div/div/div[1]/div[1]/a")).click();
    driver.findElement(By.xpath("/html/body/nav/div/a[2]")).click();
    driver.findElement(By.xpath("//*[@id='initialView']/div[1]"));
    System.out.println(driver.findElement(By.id("headingText")));
    System.out.println(driver.findElement(By.id("headingSubtext")));
    driver.findElement(By.id("identifierId")).sendKeys("anjanikmr51");
    driver.findElement(By.className("RveJvd snByac")).click();
    driver.findElement(By.className("whsOnd zHQkBf")).sendKeys("elefano**4561");
    driver.findElement(By.className("RveJvd snByac")).click();
    System.out.println(driver.getTitle());
    driver.findElement(By.xpath("//*[@id=':j3']/div/div")).click();
    }
    }

    Here is the error code :

    Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to find element with xpath == //*[@id='initialView']/div[2]
    For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
    Build info: version: '3.5.3', revision: 'a88d25fe6b', time: '2017-08-29T12:54:15.039Z'
    System info: host: 'CHANDRA-PC', ip: '192.168.1.10', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_144'
    Driver info: org.openqa.selenium.ie.InternetExplorerDriver
    Capabilities [{acceptInsecureCerts=false, browserVersion=11, se:ieOptions={nativeEvents=true, browserAttachTimeout=0, ie.ensureCleanSession=false, elementScrollBehavior=0, enablePersistentHover=true, ie.browserCommandLineSwitches=, ie.forceCreateProcessApi=false, requireWindowFocus=false, initialBrowserUrl=http://localhost:10057/, ignoreZoomSetting=false, ie.fileUploadDialogTimeout=3000, ignoreProtectedModeSettings=false}, browserName=internet explorer, pageLoadStrategy=normal, unhandledPromptBehavior=dismiss, javascriptEnabled=true, platformName=XP, setWindowRect=true, platform=XP}]
    Session ID: 99e8cbc9-b603-49b9-8cd2-de4f4a8da7f5
    *** Element info: {Using=xpath, value=//*[@id='initialView']/div[2]}
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:185)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:120)
    at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
    at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
    at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:646)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:416)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:518)
    at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:408)
    at com.google.mail.OpenGmail.main(OpenGmail.java:16)
     

    Attached Files:

    #1
  2. Karthik Shivana

    Karthik Shivana Moderator
    Simplilearn Support Alumni

    Joined:
    Apr 1, 2016
    Messages:
    674
    Likes Received:
    28

    Hi Anjani,

    This is most common error in selenium, you need to find proper x path. Even some times x path values are correct, but still we face the same issue. because web-drive will not wait so long to locate the elements in web page if the web page is down.

    In this case you need to add web driver wait function, so that driver will wait till the page launches then elements will be located properly.
     
    #2

Share This Page