user5153746
user5153746

Reputation:

Xpath always clicks on first child <li> python

I'm trying to press on few links using the code:

self.browser.find_element_by_xpath("//li[@onclick[contains(text(),"+origin_iata_code+")]]").click()

The origing_iata_code is the object in:

['FLL', 'MCO', 'AFL', 'ATM', 'AJU', 'ARU', 'AAX', 'NVT', 'BRA', 'JTC',...]

And the code I'm tring to click on had a unique thing for all but it always press just the FLL one

<li onclick="selecionou('FLL', this,'.txtBusca1', 'true', 'origem', 'Estouem1', 'FLL');">
..
</li>
<li onclick="selecionou('MCO', this,'.txtBusca1', 'true', 'origem', 'Estouem1', 'MCO');">
..
</li> 

and so on

Upvotes: 1

Views: 41

Answers (1)

Madhan
Madhan

Reputation: 5818

The problem is you forget to add quotes.

("//li[@onclick[contains(text(),'"+origin_iata_code+"')]]")

and you have to use . instead of text()

Go with this

  //li[@onclick[contains(.,'FLL')]]

or

  //li[contains(@onclick,'FLL')]

So go with

 ("//li[@onclick[contains(.,'"+origin_iata_code+"')]]")

Upvotes: 1

Related Questions