Amir
Amir

Reputation: 81

can't find element by xpath using selenium

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?

Upvotes: 1

Views: 1227

Answers (3)

Saurabh Gaur
Saurabh Gaur

Reputation: 23845

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();

Upvotes: 1

Siva
Siva

Reputation: 1149

Seems like you have a compound class, try using CSSSelector

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

Upvotes: 0

lauda
lauda

Reputation: 4173

Try this selector:

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

Upvotes: 0

Related Questions