I am searching it from 2 days but still unable to get satisfying answer..please help I am using liferay, i want to open dropdown which name is "Add" and then want to click on submit button named as "Blank Site"..and both "Add" and "Blank site" button contains dynamic values/id which changes each time..attaching image for reference..
Asked
Active
Viewed 3,081 times
3 Answers
1
Selenium supports wide range of different selectors besides byId. XPath is able to refer to text value inside the tag.
Also using almost any selector you can retrieve list that can be additionally filtered by any rules.

skyboyer
- 22,209
- 7
- 57
- 64
1
Use Xpath Contains Method:
Based on your 2 attached image, I think the button's text you are looking for is unique in the entire web page.
![]()
What you can do to fix the problem:
- For the second circumstance(
Blank Site
):- Xpath:
//li/a/span[contains(text(), "Blank Site")]
- Xpath:
Suggestions:
-
Thanks man..it works..i have applied the same structure with "Add" button as well and both works...thank allot :) – MMaggy Nov 14 '17 at 08:51
-
Brother is there any way to consider 2nd text..i have two same words in a page but i want selenium to consider 2nd one only to click.. – MMaggy Nov 14 '17 at 22:10
-
You can append `[index]` to the end of xpath string, like `//li/a/span[contains(text(), "Blank Site")][1]`. If you want to select the last element, you can use xpath in this way`//element[@name='D'])[last()]`, you can even select the penultimate element like this`//element[@name='D'])[last()-1]`. – Nov 15 '17 at 04:53
1
You can use xpath with any combination, one is already suggested by @PedroMiguel other one is like that
//*[contains(@id, 'yui-patched') and contains(@role,'menuitem')]

iamsankalp89
- 4,607
- 2
- 15
- 36