Home > Mobile >  C# Selenium navigate to Statistics on specifig Page
C# Selenium navigate to Statistics on specifig Page

Time:05-25

I am working with C# and Selenium.

On this Page i want to click on "Statistics": https://eatradingacademy.com/software/forex-historical-data/

I tried out to click with several modified codes. Fairly try & error. I dont understand XPath until now, but i am working on it.

Can someone here help me out? What lines of Code are needed to click this Link?

//webdriver.FindElement(By.XPath("//a[text()='Settings']")).Click();
//webdriver.FindElement(By.XPath("//li[@class='nav-item']/a[text()='Settings']")).Click();
// webdriver.FindElement(By.XPath("//li/a/span[.='Settings']")).Click();
//webdriver.FindElement(By.XPath("//a[contains(.,'Settings')]")).Click();
//webdriver.FindElement(By.XPath("//a[contains(text(),'Settings')]")).Click();

Code of Page

CodePudding user response:

Try below XPath

//a[translate(normalize-space(.), 'ABCDEFGHIJKLMNOPQRSTUVWXYZ', 'abcdefghijklmnopqrstuvwxyz')='statistics']

CodePudding user response:

This is a special case because the element you want to click is located in an iFrame.
To locate such element, you'll first have to switch the focus to the iFrame.
You can do this like this:

webdriver.SwitchTo().Frame(webdriver.findElement(By.id("data-app-frame"));

After that you can locate the element within the iFrame. I would suggest taking a combination of class and text in this case because if you only search for the text, another element which contains just the word 'Settings' or 'Statistics' may be located instead.
This would result in following line:

webdriver.FindElement(By.XPath("//a[@class='nav-link panel-switch' and contains(text(), 'Statistics')]")).Click();
  • Related