Coder1994UK Coder1994UK - 6 days ago 7
Vb.net Question

Selenium with VB.NET - Cannot find element

I'm new to Selenium, and I've stumbled upon an error.

I'm trying to download a specific file from a website(seen in code), when I get to the last section of the website where the download link becomes available, I'm having trouble selecting the 'Download Full Securities List'. I've tried with XPath CSS Selectors and so on.

Could any of you tech-savvy guys out there kindly suggest a fix/recommendation?

Any help would be great!

Thank you,
Cihan

Sub downloadDBX()
'Initalise Chrome Browser For Execution
Dim driver As IWebDriver
driver = New ChromeDriver("C:\Users\cihan\Documents\Selenium")

'Navigate to the DBx Website
driver.Navigate().GoToUrl("https://etf.deutscheam.com/GBR/ENG/Disclaimer/Institutional")

'Get ElementID to navigate DBX Website
Dim agreeTerms As IWebElement = driver.FindElement(By.XPath("//*[@id='form']/div[3]/div[2]/div[2]/div/div/div[1]/div/div/div/div[2]/div[3]/div[2]/div/div[2]/div[1]/a"))
System.Threading.Thread.Sleep(1000)
agreeTerms.Click()

'Navigate to the equities section of DBx
Dim equitiesPage As IWebElement = driver.FindElement(By.XPath("//*[@id='form']/div[3]/div[2]/div[3]/span[1]/div/div/div[2]/div[3]/div/div[2]/div/ul/li[2]/a"))
System.Threading.Thread.Sleep(1000)
equitiesPage.Click()

'click relevant fund
Dim myFundInformation As IWebElement = driver.FindElement(By.PartialLinkText("ATX UCITS ETF (DR)"))
System.Threading.Thread.Sleep(1000)
myFundInformation.Click()

'change to "ETF Information tab" to gather required data
Dim myFundHoldings As IWebElement = driver.FindElement(By.XPath("//*[@id='ctl02_ctl15_ctl00_ctl01_126']/span"))
System.Threading.Thread.Sleep(1000)
myFundHoldings.Click()


'download my holdings
Dim myData As IWebElement = driver.FindElement(By.XPath("//*[@id='ctl02_ctl15_ctl00_container']div[2]/div[3]/div/div[4]/div[2]/div/a/div[2]/span"))
System.Threading.Thread.Sleep(1000)
myData.Click()
End Sub

Answer

this was solved by searching for the link text rather than the XPATH of the download link. Before and after as follows:

'download my holdings
Dim myData As IWebElement = driver.FindElement(By.XPath("//*[@id='ctl02_ctl15_ctl00_container']div[2]/div[3]/div/div[4]/div[2]/div/a/div[2]/span"))
System.Threading.Thread.Sleep(1000)
myData.Click()

now:

    'download my holdings
    Dim myData As IWebElement = driver.FindElement(By.LinkText("Download Full Securities List"))
    System.Threading.Thread.Sleep(1000)
    myData.Click()
Comments