KRISHNA KATAMANENI
KRISHNA KATAMANENI

Reputation: 25

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"name"}

enter image description hereSource

<input id="name" name="name" type="text" style="box-sizing:border-box;-moz-box-sizing:border-box;position:absolute;left:130px;top:50px;width:220px;">

This is my code

WebElement VARName = driver.findElement(By.id("name"));
    VARName.sendKeys("Krishna-05");

The page in this subject is a pop up page.

Error:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"id","selector":"name"} (Session info: chrome=61.0.3163.100) (Driver info: chromedriver=2.32.498550 (9dec58e66c31bcc53a9ce3c7226f0c1c5810906a),platform=Windows NT 10.0.10240 x86_64) (WARNING: The server did not provide any stacktrace information) Command duration or timeout: 0 milliseconds

I tried finding with css,xpath,name etc and no use. All of them exhibit the same error. I'm using Selenium Webdriver with Java on Eclipse.

package open_chrome;

import java.util.Iterator;
import java.util.Set;
import java.util.concurrent.TimeUnit;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;
import org.openqa.selenium.support.ui.Select;

public class Chrome_Driver {

public static void main(String[] args) throws InterruptedException{

    WebDriver driver = new ChromeDriver();
    driver.manage().window().maximize();
    driver.get("https://<website.com>/");

    driver.findElement(By.id("email")).sendKeys("[email protected]");
    driver.findElement(By.id("password")).sendKeys("Test1234");
    driver.findElement(By.cssSelector("body > div:nth-child(1) > div > div > 
    form > div:nth-child(5) > button")).click();
    //Adding New VAR

    driver.findElement(By.id("ext-gen224")).click();
    driver.findElement(By.id("ext-gen367")).click();
    String parentWindow = driver.getWindowHandle();
//      Set<String> handles =  driver.getWindowHandles();
    for(String childWindow:driver.getWindowHandles())
    {
        driver.switchTo().window(childWindow);
        driver.findElement(By.id("name")).sendKeys("Krishna-05");
    }

Upvotes: 0

Views: 4140

Answers (3)

user12105837
user12105837

Reputation: 11

You should add the following code line:

driver.manage().timeouts().implicitlyWait(120,TimeUnit.SECONDS);

System runs that code in fraction of second that's you can't see, Give this code.

Upvotes: 1

iamsankalp89
iamsankalp89

Reputation: 4739

You can use any locator, seems issue with wait I guess, try explicit and Implicit wait

driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
WebElement VARName = driver.findElement(By.id("name"));
VARName.sendKeys("Krishna-05");

Or with Explicit wait

WebDriverWait wait = new WebDriverWait(driver,20);
WebElement VARName= wait.until(ExpectedConditions.visibilityOfElementLocated(By.id("name")));
VARName.sendKeys("Krishna-05")

Second thing check whether element is in frame or not, if it is in frame first switch in frame and then use above code

Upvotes: 1

nairavs
nairavs

Reputation: 509

There can be many facts . Does your element visible . I mean for example may be you have a scrolling ? May be there is iframe ? If this will not help please provide the class of your test with start and all steps , browser info... I will try to help.

Upvotes: 0

Related Questions