0

I am trying to click on the search area in this page http://test1.absofttrainings.com

Code:

import java.util.concurrent.TimeUnit;

import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;


public class FindProduct  {

    @Test
    public void findProduct(){

        WebDriver driver= new FirefoxDriver();
        driver.get("http://test1.absofttrainings.com/");

        WebElement search_link=driver.findElement(By.xpath("//span[@id='et_search_icon']"));

        Actions action= new Actions(driver);
        action.moveToElement(search_link).build().perform();


        driver.findElement(By.xpath("//span[@id='et_search_icon']")).click();


    }

}

I am getting Element Not visible exception. I have tried using implicitlyWait but that did not work either. Your suggestion/advise is welcome.

Sheikh Rahman
  • 895
  • 3
  • 14
  • 29

1 Answers1

0

Try using

driver.findElement(By.id("et_top_search")).click();

or use JS

((JavascriptExecutor)driver).executeScript("document.getElementById('et_search_icon').click();");

Have a look at this link How to force Selenium WebDriver to click on element which is not currently visible?

There are certain rules based on which "Selenium" determines an element is visible or not (make sure you look at computed style):

  1. visibility != hidden
  2. display != none (is also checked against every parent element)
  3. opacity != 0 (this is not checked for clicking an element)
  4. height and width are both > 0
  5. for an input, the attribute type != hidden

May be the span element is NOT matching any of the above criteria.

The span tag has a height and width as 0 and hence selenium is unable to find the element. See the attachmententer image description here

Community
  • 1
  • 1
shank087
  • 492
  • 8
  • 17