2017-07-24 89 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