0

I am facing the issue . Kindly assist. The HTML Code snippet is attached

I am getting the error as enter image description here

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@id='search']"}

The code

//click login button
    driver.findElement(By.id("save_sla")).click();
    driver.manage().timeouts().pageLoadTimeout(120, TimeUnit.SECONDS);
    WebElement wb=driver.findElement(By.xpath("//input[@id='search']"));
        
    WebDriverWait wait=new WebDriverWait(driver,30);

    wait.until(ExpectedConditions.elementToBeClickable(wb)).sendKeys("xyz");
    driver.findElement(By.xpath("//i[@id='search001a']")).click();

enter image description here

6
  • 2
    The highlighted line in the screenshot is not relevant to the Exception occurred. Please check.
    – kaweesha
    Jun 27, 2020 at 18:28
  • @kaweeshaThe xpath provided is able to find the element but when i execute the code it shows "noElementFoundException" By.xpath("//input[@id='search']"
    – RinJai
    Jun 28, 2020 at 2:34
  • I also tried with css selector By.cssSelector("#search"). But still getting "noElementFoundException"
    – RinJai
    Jun 28, 2020 at 2:43
  • NoSuchElementException can be occurred due to many reasons. Refer the accepted answer in here; NoSuchElementException, Selenium unable to locate element. Without looking at the complete DOM its difficult to understand a reason. If you are okay, share the page URL.
    – kaweesha
    Jun 28, 2020 at 4:27
  • @kaweesha ..issue caused by the page not completely loaded when I find the element.Now i added more delay which i never expected and issue is resolved .Thanks for your suggestions and time
    – RinJai
    Jun 28, 2020 at 11:05

1 Answer 1

0

You must be getting the wrong input tag. You're locating the search box with //input[@id='search'], I guess what you need is //input[@id='search_submit'].

Not the answer you're looking for? Browse other questions tagged or ask your own question.