Topto Topto - 1 month ago 13
Python Question

Can' locate a certain element using xpath locator in python

I've written an

xpath
to get to a certain element but unfortunately it is not being able to.

I can't understand where i'm getting deviated. Hope somebody will provide me with a little help.

I'm trying to locate the address from the below elements.

Here are the elements:

<div class="detail-contact-address">
<i class="fa fa-map-o"></i>
Address:36 Sukhumvit, Soi 15, Wattana, Klongtoey-nua, Bangkok 10110, Thailand
</div>


I was trying with:

//div[@class='detail-contact-address']/*[contains(@class,'fa-map-o')]/../text()

Answer Source

User below xpath to get the text :

//div[@class='detail-contact-address']

OR based on some string match

//div[@class='detail-contact-address'][contains(.,'Address')]

So you will get the text like

print driver.find_element_by_xpath("//div[@class='detail-contact-address']").text