0

I'm trying to write some automated java tests using selenium and PhantomJS driver but I'm having a big problem trying to interact with a text field.

http://www.jigsaw-online.com/ I'm trying to send some text to the search box but I've tried lots of different find by locators and I always get ElementNotVisibleException when I try to send keys to the field

@FindBy(xpath="//header//form[@id='search']//input[@type='search']")
@FindBy(xpath="//input[@name='w']")
@FindBy(xpath="//form[@id='search']//input[@type='search']")

I know all of these xpath's are correct because I can get the attributes from it in the test.

The only thing I can think of is that if you scroll down the page the header follows.

Can anybody suggest a way I can send keys to this field?

Doctor Who
  • 1,287
  • 5
  • 25
  • 46
  • 2
    Quite a tough one since you are using a headless browser driver... Might be you need to scroll it into view. Check out this [question](http://stackoverflow.com/questions/3401343/scroll-element-into-view-with-selenium) – Ceiling Gecko Nov 10 '15 at 12:03
  • Thank you, the scrolling didn't fix it but using javascript with the argument[0] like in that example I am able to call .value= on the element and can send keys to it. – Doctor Who Nov 10 '15 at 15:37

1 Answers1

0

The id of the Search box on the top of that page is not search, but sli_search_1.

So the simplest xpath would be //*[@id="sli_search_1"].

On the other hand, why don't you just find that element by id? Something like:

searchBox = driver.findElement(By.Id("sli_search_1"));
searchBox.sendKeys("hello");

Hope it helps.

makeMonday
  • 2,303
  • 4
  • 25
  • 43
  • Sorry my xpath was a bit messed up, if you're on the home page or do a search you can use slightly different xpath to get the field. I've already tried what you suggested but that doesn't work, try it yourself you will see the exception is thrown. I've managed to enter text in the field using javascript so I guess I will have to use JS instead – Doctor Who Nov 10 '15 at 12:43