1

I am using beta.speedtest.net to check my network speed. I want to automate this process using Selenium(open to other frameworks as well). This automation process consists of few steps

  1. Clicking on Change Server link
  2. Type my preferred server location
  3. Choose the server of my choice
  4. Run the test
  5. Get the result of each test (in any way possible)

How I am proceeding

    public void RunTheTest()
    {
        IWebDriver driver = new ChromeDriver();
        driver.Manage().Window.Maximize();
        driver.Navigate().GoToUrl("http://beta.speedtest.net");
        driver.FindElement(By.LinkText("Change Server")).Click();
    }

Unable to find any element that is critical for my process.

Manvinder
  • 4,495
  • 16
  • 53
  • 100
  • Try this `driver.findElement(By.xpath("//a[@class='btn-server-select' and contains(text(), 'Change Server')]")).click();` – sen4ik Jun 23 '17 at 19:37
  • @sen4ik Your suggestion works, can you please post it as answer with the reason why it won't work just with "ByText" method, it could help future users. Also do I need to find rest of the elements with same process as well – Manvinder Jun 23 '17 at 19:42

2 Answers2

2

The LinkText won't work in your case because the text contains leading and trailing white spaces. Those may be Non-Breaking SPaces

enter image description here

So you have to go with xpath with contains or normalize-space

//a[normalize-space(text())='Change Server']

//a[contains(text(),'Change Server')]

If you want simple then go with className

btn-server-select

as there is only one element with such className

Madhan
  • 5,750
  • 4
  • 28
  • 61
1

Try this:

driver.findElement(By.xpath("//a[@class='btn-server-select' and contains(text(), 'Change Server')]")).click();
sen4ik
  • 407
  • 4
  • 16
  • Upvote for correct answer but accepted answer has reason why normal approach won't work and more clarification for future users. Thanks – Manvinder Jun 25 '17 at 09:21