2017-07-24 83 views
-1

我尝试使用硒和关键字by,访问类,并出现以下错误:引用错误通过没有定义

ReferenceError: By is not defined 
    at Object.<anonymous> (C:\selenium\hello_world.js:11:18) 
    at Module._compile (module.js:569:30) 
    at Object.Module._extensions..js (module.js:580:10) 
    at Module.load (module.js:503:32) 
    at tryModuleLoad (module.js:466:12) 
    at Function.Module._load (module.js:458:3) 
    at Function.Module.runMain (module.js:605:10) 
    at startup (bootstrap_node.js:158:16) 
    at bootstrap_node.js:575:3 

程序是非常简单的

var webdriverio = require('webdriverio'); 
var options = { 
     desiredCapabilities: { 
     browserName: 'chrome' 
     } 
    }; 
var client = webdriverio.remote(options); 
client 
    .init() 
    .url('https://mail.google.com') 
    .findElement(By.className("TnvOCe k6Zj8d XraQ3b")).click() 
    .end(); 
+1

这似乎是Node.js,是吗?它看起来像你混淆了不同语言的功能乍一看 – mrfreester

+0

@mrfreester是... – jamijam

回答

2

您正在使用webdriverio,而不是Selenium。代码应该如下。

client 
    .init() 
    .url('https://mail.google.com') 
    .click('.TnvOCe.k6Zj8d.XraQ3b') 
    .end(); 


你可以找到webdriverio API here

+0

我想出了在此期间......很愚蠢...... – jamijam