1
votes

I try this xpath but I don't know how to continue ? i have 2 objects in popup menu and i want to select the first one

the html of the page is:

</div>
<input class="sprite form-enter" type="submit" value="" name="wobi">
</div>
<div class="container">
<img src="/_media/home/img/icons/pension.png">
<div class="login-text-container">
<a class="sprite form-enter" href="https://pension.wobi.co.il/login" value="" name="pension" type="submit"></a>
</div>
</div>

the java code is:

driver.findElement(By.xpath("//input[@class='sprite form-enter' and input//@name='wobi']")).click();
Thread.sleep(2000);

After execution of code I got the following exception:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//input[@class='sprite form-enter' and input/@name='wobi']"}

What's wrong in my code?

3
Do you mean you have two element with the same class sprite form-enter and name wobi?? - Saurabh Gaur
your XPath is wrong better try and check if it works in Firebug / Firepath - Mrunal Gosar

3 Answers

1
votes

Actually you are try with wrong xpath, the correct xpath would be :-

//input[@class='sprite form-enter' and @name='wobi']

But I would suggest you, try using By.cssSelector() here because it would be much faster than xpath as below :-

driver.findElement(By.cssSelector("input.sprite.form-enter[name = 'wobi']")).click();
0
votes

Try this selector:

//input[@class='sprite form-enter'][@name='wobi']
0
votes

Seems like you have a compound class, try using CSSSelector

driver.findElement(By.cssSelector(".sprite.form-enter")).click();