2016-12-14 68 views
0

我试图用webdriverIO点击网页中的链接。 我可以导航到google.com页面,然后输入搜索词。如何点击webdriverIO中的链接

但是当我尝试点击一个包含我想要的文本的链接时,它不会点击链接。

我在做什么错:

这里是我的代码:

var webdriverio = require('webdriverio'); 
var options = { 
    desiredCapabilities: { 
     //browserName: 'phantomjs' 
     browserName: 'chrome' 
    } 
}; 
webdriverio 
    .remote(options) 
    .init() 
    .url('http://www.google.com') 
    .setValue('*[name="q"]','webdriverio') 
    .click('*[name="btnG"]') 
    .pause(1000) 
    .getTitle().then(function(title) { 
     console.log('Title was: ' + title) 
    }) 
    .getText('=webdriver.io').then(function(text) { 
     console.log('Title was: ' + text); // outputs: "WebdriverIO" 
    }) 
    .end(); 

我正在webdriverIO与node.js的v6.9.2和硒独立服务器3.0.1。

谢谢。

回答

1

找到了!!!

使用:

.click('[href="http://webdriver.io/"]') 

此格式为我工作。

0

看起来他们已将“google搜索”按钮的名称更改为“btnK”。尝试在单击命令中用'btnK'替换'btnG',看看它是否有效。

<input value="Google Search" aria-label="Google Search" name="btnK" type="submit" jsaction="sf.chk"> 
+0

不,这不是问题。我可以到google.com并搜索webdriverio就好了。它在页面本身的链接上拣选,这是我的问题。 – ironmantis7x