-2

I am trying to access data from XPath for the below data. I wanted to get the Hostname - 192.81.xx.xx and ISP - Random

<div class="left">
 <p class="information">
    <span>Hostname</span>
    <span>192.81.xx.xx</span>
 </p>
 <p class="information">
    <span>ISP</span>
    <span>Random</span>
 </p>
</div>

Xpath I've Tried - //div[@class="left"]//p[@class="information"]//span[contains(text(), "Hostname:")]

1 Answers1

1

this xpath

//div[@class="left"]//p[@class="information"]//span

will return 4 nodes.

<span>Hostname</span>
<span>192.81.xx.xx</span>
<span>ISP</span>
<span>Random</span>

based on the HTML that you've shared.

you should use find_elements that will return list of web elements.

Also, if you use the above XPath with find_element it will always fetch the first matching node which is <span>Hostname</span>

to get specific node:

  1. to get 192.81.xx.xx use the below XPath:

    //div[@class="left"]//p[@class="information"]//span[1]
    
  2. for random:

    //div[@class="left"]//p[2][@class="information"]//span[2]
    
cruisepandey
  • 28,520
  • 6
  • 20
  • 38