Manoj Kabule
Manoj Kabule

Reputation: 11

How to handle dynamic id

I am trying to explore log In button xpath with this site https://www.componence.com/login, by just recording and play back.Then I tried to get it through firepath and chrome browser default xpath copier.

But it looks like every time submit button xpath get changed with page load. I got following xpath for "Sign IN" button.

.//*[@id='yui_patched_v3_11_0_1_1487250469606_202']
.//*[@id='yui_patched_v3_11_0_1_1487251369606_202']
.//*[@id='yui_patched_v3_11_0_1_1487250229606_202']
.//*[@id='yui_patched_v3_11_0_1_1487254369606_202']

Can you please help me to retrieve correct xpath of Sign IN button which I can use with selenium IDE?

Upvotes: 1

Views: 891

Answers (2)

lauda
lauda

Reputation: 4173

I will have to disagree with the second statement of @Andersson, since it will work for .com but not for .nl.

As I see the site has a second language and my opinion is to avoid using selectors based on text on a multi-language environment.

Also as I see the id seems does not have a meaningful value, in this case try to identify a unique parent section and go from there.

One option for css/xpath would be:

css: form.sign-in-form button

xpath: //form[contains(@class, 'sign-in-form')]//button

Upvotes: 2

Andersson
Andersson

Reputation: 52685

You can use below XPath to handle dynamic id:

//button[starts-with(@id, "yui_patched_v3_11_0_1_")]

But better solution is to use text content of element:

//button[normalize-space(text())="Sign In"]

Upvotes: 2

Related Questions