Search code examples
vbaselenium-webdrivercss-selectorswebdriver

VBA Selenium can't find correct locator strategy


I am trying to click on the "Exporter toutes les versions de chaque indisponibilité (.csv)" link on the following site:

https://www.edf.fr/groupe-edf/ambition-neutralite-co2-pour-edf-a-l-horizon-2050/optimisation-et-trading/listes-des-indisponibilites-et-des-messages/liste-des-indisponibilites

I have tried multiple things, but selenium can't find it to click it. I have tried multile things among them:

bot.FindElementByXPath("//*[@id='wrapper']/div/form/div[1]/ul/li[1]/a").Click
bot.FindElementByCss("#zoneLinks > ul > li:nth-child(1) > a").Click
bot.FindElementByXPath("//*[@id="zoneLinks"]/ul/li[1]/a").Click

Thank you for your help guys.

Best, Eliot TABET


Solution

  • The element in inside an iframe, You need to switch it first.

    Use below css selector

    bot.SwitchToFrame .FindElementByCss("iframe.iframe-responsive", timeout:=10000)
    
    bot.FindElementByCss("li.csv:nth-of-type(1)> a").Click
    

    enter image description here