Skip to main content
added 179 characters in body
Source Link
NarendraR
  • 1.6k
  • 1
  • 17
  • 35

As far as i know xpath doesn't depends on any browser. Make sure you have created correct xpath it will work.

Second : It's depend on your tag which attribute it has and how efficient you are in xpath.

For example this is the simple hyperlink:

<a href="https://stackexchange.com/questions?tab=hot" name="hotnetwork" class="js-gps-track">Hot Network Questions</a>

So here i can create the xpath to locate the same in different ways like :

//a[@name='hotnetwork']

OR

//a[@class='js-gps-track']

OR combine both attribute for uniqueness like :

//a[@name='hotnetwork'][@class='js-gps-track']

OR if you want to access the link using its text then you can use contains() method

//a[contains(text(),'Hot Network')]

Note : It will locate the element based on match found with your given string (Hot Network)

If you require to locate an element if self or its child tag contains some text then using dot . in contains method as you are using :

 //a[contains(.,'Hot Network')]

OR you can use text() method like :

//a[text()=' Hot Network Questions'] 

While using text() method you have to pass the full link text including spaces else it won't work.

As far as i know xpath doesn't depends on any browser. Make sure you have created correct xpath it will work.

Second : It's depend on your tag which attribute it has and how efficient you are in xpath.

For example this is the simple hyperlink:

<a href="https://stackexchange.com/questions?tab=hot" name="hotnetwork" class="js-gps-track">Hot Network Questions</a>

So here i can create the xpath to locate the same in different ways like :

//a[@name='hotnetwork']

OR

//a[@class='js-gps-track']

OR combine both attribute for uniqueness like :

//a[@name='hotnetwork'][@class='js-gps-track']

OR if you want to access the link using its text then you can use contains() method

//a[contains(text(),'Hot Network')]

Note : It will locate the element based on match found with your given string (Hot Network)

OR you can use text() method like :

//a[text()=' Hot Network Questions'] 

While using text() method you have to pass the full link text including spaces else it won't work.

As far as i know xpath doesn't depends on any browser. Make sure you have created correct xpath it will work.

Second : It's depend on your tag which attribute it has and how efficient you are in xpath.

For example this is the simple hyperlink:

<a href="https://stackexchange.com/questions?tab=hot" name="hotnetwork" class="js-gps-track">Hot Network Questions</a>

So here i can create the xpath to locate the same in different ways like :

//a[@name='hotnetwork']

OR

//a[@class='js-gps-track']

OR combine both attribute for uniqueness like :

//a[@name='hotnetwork'][@class='js-gps-track']

OR if you want to access the link using its text then you can use contains() method

//a[contains(text(),'Hot Network')]

Note : It will locate the element based on match found with your given string (Hot Network)

If you require to locate an element if self or its child tag contains some text then using dot . in contains method as you are using :

 //a[contains(.,'Hot Network')]

OR you can use text() method like :

//a[text()=' Hot Network Questions'] 

While using text() method you have to pass the full link text including spaces else it won't work.

Source Link
NarendraR
  • 1.6k
  • 1
  • 17
  • 35

As far as i know xpath doesn't depends on any browser. Make sure you have created correct xpath it will work.

Second : It's depend on your tag which attribute it has and how efficient you are in xpath.

For example this is the simple hyperlink:

<a href="https://stackexchange.com/questions?tab=hot" name="hotnetwork" class="js-gps-track">Hot Network Questions</a>

So here i can create the xpath to locate the same in different ways like :

//a[@name='hotnetwork']

OR

//a[@class='js-gps-track']

OR combine both attribute for uniqueness like :

//a[@name='hotnetwork'][@class='js-gps-track']

OR if you want to access the link using its text then you can use contains() method

//a[contains(text(),'Hot Network')]

Note : It will locate the element based on match found with your given string (Hot Network)

OR you can use text() method like :

//a[text()=' Hot Network Questions'] 

While using text() method you have to pass the full link text including spaces else it won't work.