Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

I tried to input phone numbers in the field but it gives me an error

    Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element

Here is the code:

    driver.get("https://marswebtdc.tdc.vzwcorp.com/cdl/lte/fdr_llc/fdr.jsp?3gOr4g=4g");
    driver.manage().window().maximize();
    driver.manage().timeouts().implicitlyWait(15, TimeUnit.SECONDS);
    driver.findElement(By.xpath("//*[@id='content column']/table[1]/tbody/tr/td/form/b/table/tbody/tr/td/table/tbody/tr[2]/td[4]/input")).click();
    driver.findElement(By.xpath("//*[@id='content column']/table[1]/tbody/tr/td/form/b/table/tbody/tr/td/table/tbody/tr[2]/td[4]/input")).clear();

    driver.findElement(By.xpath("//*[@id='content column']/table[1]/tbody/tr/td/form/b/table/tbody/tr/td/table/tbody/tr[2]/td[4]/input")).sendKeys("9083071303");

this is internal site you cant load the page.

I assume the sendkey() doesnt work for this field. is there any element i can use instead sendkey().

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
209 views
Welcome To Ask or Share your Answers For Others

1 Answer

Exception org.openqa.selenium.NoSuchElementException tells the element not present on page when action is performed.

This may be because of either XPATH is not correct or element is not appeared on page before action is called.

Please run code in debug mode to find exact problem.

Here is quick example of google search box. I have put wrong id to make code fail. In this case I get the exception. If we correct the id "gbqfq" the code works fine.

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class GoogleSearchUsingSelenium {

    public static void main(String[] args) {

        WebDriver driver = new FirefoxDriver();
        driver.get("http://www.google.com");

        try
        {
            WebElement searchBox = driver.findElement(By.id("gbqfq1")); //Incorrect ID here
            searchBox.sendKeys("Cheese");
        }
        catch(Exception e){
            System.out.println("Eelemnt Not Found : "+e.getMessage());
        }

        driver.close();

    }

}

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...