gartenkralle
gartenkralle

Reputation: 697

Not working xpath in selenium

The first xpath is working whereas the second not:

First:

"//*[@id='j_idt46:j_username']";

Second:

"//*[contains(@id,'username']";

Why?

Upvotes: 1

Views: 62

Answers (1)

Naman
Naman

Reputation: 32036

To what could be figured out of the information provided, the way you are using contains is possibly inappropriate :

  1. As mentioned by @TuringTux - //*[contains(@id,'username')] could be the possible change if the same lined goes as it is in your code.

  2. Also a good practice to follow in //*[contains(@id,'username')] , would be to replace * by an element type in html.

  3. And lastly there could be chances when you are trying to access elements using //*[contains(@id,'username')], you may be ending up getting a list of these similar WebElements while you might be trying to access only a single at the same time.

Upvotes: 2

Related Questions