0

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");
    }
1
  • 1
    There could be many reasons why this is happening... what have you tried to solve it other than trying different locators? Waits? Is there an IFRAME? Commented Nov 16, 2017 at 21:42

3 Answers 3

1

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

Sign up to request clarification or add additional context in comments.

1 Comment

visibilityOfElementLocated does not check if element is in iframe. It only invokes isDisplayed() method on the element. Besides that, this is a good answer.
1

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.

Comments

0

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.

10 Comments

I can't add the image as a comment but please check the question, I've added it there. Hopefully that will clear some clouds.
Is div Option_0 visible ? I mean at firts try to find step by step the input . One more question may be before that input there is another element with the same name ? Check this too .also you can try to find element in html content too. Try this too. If this will not help provide me your class with url , setup etc .
Also is this normal page ? May be popup or it is on other tab, window ?
Another pop up window
So first you should switch to that window maybe web driver Alert class will help . After that start finding you can use pause for 2 sec before finding the element to be sure that it exists
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.