Search code examples
pythonseleniumselenium-webdriverxpathfindelement

Find correct xpath with selenium Python


I'm currently working on a project with Selenium and webdriver. So far so good I can navigate through the website using selenium without any problem however, I would need to click on a specific icon to slides through to a date and time table. Issue is when looking at the HTML I have no idea what to locate with Selenium in order to click on that icon.

HTML sample:

<a _ngcontent-oyt-c155="" class="btn btn-soft-primary day-selector-navbutton"><i _ngcontent-oyt-c155="" class="fa fa-chevron-right"></i></a>

Usually I'm locating items by name, ID or Class but in that case I don't know where to got with.

Should I look for the xpath instead ?


Solution

  • Accordingly to what you have shared here this XPath should work:

    '//a[@class="btn btn-soft-primary day-selector-navbutton"]//i[@class="fa fa-chevron-right"]'
    

    I can't be completely sure if this locator is unique or if there is no iframe there etc.
    You will possibly need to add some kind of wait here too. If so you should preferably use Expected Conditions explicit waits.