1

I am working on automation testing website www.benjerry.com/. I can't inspect serch button. I succesfully enter credential in search field, but can't click on search button. I try all kind of combinations, but still nothing. Can someone please help me?

1

Picture with marked problem

Code line:

driver.findElement(By.cssSelector("div.btn-submit")).click();
Jesse
  • 3,522
  • 6
  • 25
  • 40
Gru Grux
  • 43
  • 3

2 Answers2

0

Try following line of code:

driver.findElement(By.xpath("(//button/span[contains(.,'Search')])[2]")).click();
Kushal Bhalaik
  • 3,349
  • 5
  • 23
  • 46
  • I am new at automatisation, can u explain me please, how did U solve that problem or just to tell me what kind of litereture should i read, so that i can solve that situation by myselfe next time? I would like to do it by myselfe next time:) – Gru Grux Apr 14 '18 at 15:16
  • go through this article here: https://www.guru99.com/xpath-selenium.html and search for XPATH and XPATH AXES tutorials on google – Kushal Bhalaik Apr 14 '18 at 15:23
0

As you have already accepted the answer given from @kushal. I'd like to highlight some points that could be useful in your Automation Journey .

You can use this cssSelector : input[id='searchTerm'] ~button>span

your code would like this :

driver.findElement(By.cssSelector("input[id='searchTerm'] ~button>span")).click();

Here are some benefits of using this cssSelector :

  1. cssSelector are more consistent than Xpath.

  2. Xpath Provided by Kushal contains numeric that is [2], which is never gonna be consistent , your test may fail if Dev would put one more span inside Button Tag. So in case if you still want to go with Xpath , then your Xpath should look like this :

    //input[@id='searchTerm']/following-sibling::button/span

You can find the difference between cssSelector and Xpath here :

What is the difference between css-selector & Xpath? which is better(according to performance & for cross browser testing)?

cruisepandey
  • 28,520
  • 6
  • 20
  • 38