How to locate an element by partially comparing its attributes in XPath?

0 votes
How to locate an element by partially comparing its attributes in XPath?
Jun 21 in Selenium by Lakshya

edited Jun 21 82 views

1 answer to this question.

0 votes

Hey Lakshya, you can locate an element by partially comparing its attributes in XPath, as XPath supports the contains() method. It allows partial matching of attribute’s value and thus helps when the attributes use dynamic values while having some fixed part. See the below example to understand better:

xPath usage => //*[contains(@section, 'mobiles')]

The above expression would match all values of section attribute having the word ‘mobiles’ in them.

answered Jun 24 by Abha
• 27,180 points

Related Questions In Selenium

0 votes
1 answer

How to select an Object by its class in Selenium?

When it comes to Selenium, XPath will ...READ MORE

answered Apr 13, 2018 in Selenium by king_kenny
• 3,650 points
72 views
0 votes
1 answer

How to locate an element by tagname?

TagName can be used with Group elements ...READ MORE

answered Jan 17 in Selenium by Frankie
• 9,810 points
76 views
0 votes
1 answer

How to use JavaScript in selenium to click an Element?

Executing a click via JavaScript has some ...READ MORE

answered Apr 13, 2018 in Selenium by Shubham
• 13,350 points
15,402 views
0 votes
1 answer
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,110 points
1,147 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,150 points
1,247 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,150 points
1,003 views
0 votes
1 answer

How to stop test execution in Selenium if an error occured?

Hey Fatima, if you are using any ...READ MORE

answered Jul 4 in Selenium by Abha
• 27,180 points
465 views
0 votes
1 answer

How to insert a file in Attach File in Gmail by selenium java ?

Hey Siva, to insert a file in ...READ MORE

answered Jul 17 in Selenium by Abha
• 27,180 points
359 views