我可以使用Selenium进行自动速度测试吗?

时间:2017-06-23 19:28:55

标签: selenium automation ui-automation speed-test

我正在使用beta.speedtest.net检查网络速度。我想使用Selenium自动化这个过程(也可以打开其他框架)。该自动化过程包含几个步骤

  1. 单击“更改服务器”链接
  2. 键入我的首选服务器位置
  3. 选择我选择的服务器
  4. 运行测试
  5. 获取每项测试的结果(以任何可能的方式)
  6. 我如何进行

        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();
        }
    

    无法找到对我的流程至关重要的任何元素。

2 个答案:

答案 0 :(得分:1)

试试这个:

driver.findElement(By.xpath("//a[@class='btn-server-select' and contains(text(), 'Change Server')]")).click();

答案 1 :(得分:1)

LinkText在你的情况下不会起作用,因为文本包含前导和尾随空格。那些可能是非破坏性的空间

enter image description here

所以你必须使用包含或normalize-space

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

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

如果你想要简单,那就去className

btn-server-select

因为只有一个元素具有这样的className

相关问题