Selenium webdriver JavaScript无法点击链接

时间:2016-03-18 15:04:11

标签: javascript selenium mocha

<a id="compareCompanies" b:onclick="needsController.showQuotes = true;" href="#">Compare companies</a>

使用Mocha的Selenium Webdriver JavaScript代码:

driver.wait(function () {
    driver.findElement(webdriver.By.id("compareCompanies"));
}, 5000);

var compareCompaniesLink = driver.findElement(webdriver.By.id("compareCompanies"));

compareCompaniesLink.click();

我得到的错误是:

  

NoSuchElementError:无法找到元素:{&#34;方法&#34;:&#34; CSS   选择&#34;&#34;选择器&#34;:&#34; * [ID = \&#34; compareCompanies \&#34;]&#34;}

1 个答案:

答案 0 :(得分:0)

似乎错误就在这里:

原文:

var compareCompaniesLink = driver.findElement(webdriver.By.id("compareCompanies"));

更新:

var compareCompaniesLink = driver.findElement(By.id("compareCompanies"));