javascript - Selenium-Webdriver, driver.findElement(...).getLocation 不是一个函数,为什么?

标签 javascript node.js selenium selenium-webdriver

我正在尝试在 Selenium 元素上调用 .getLocation(),如下代码所示。

const webdriver  = require('selenium-webdriver');

const driver = new webdriver.Builder()
        .forBrowser('firefox')
        .build();

driver.findElement(webdriver.By.css('.xxxx'))
        .getLocation()
        .then(l => {
           console.log('got a position');
           console.log(l);
        });

但我有

Unhandled promise rejection (rejection id: 1): TypeError: driver.findElement(...).getLocation is not a function

我做错了什么? 或者我需要导入其他库吗?

谢谢!

最佳答案

JavaScript 中没有用于 WebElementgetLocation()。你有getRect()

driver.findElement(webdriver.By.css('.xxxx')).getRect()

关于javascript - Selenium-Webdriver, driver.findElement(...).getLocation 不是一个函数,为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53312388/

相关文章:

javascript - 无法在 Fancybox 底部添加 20px 的内边距

javascript - 在递归函数中首先返回最后一项

javascript - 数据库支持的工作队列

node.js - 在代理后面使用 Node gyp 安装 bcrypt

javascript - 在 node.js (node-soap) 中向 SOAP 消息添加属性

python - WebDriver异常: Message: chrome not reachable after long time

javascript - Typescript/Javascript 对象

javascript - 如何在mapbox GL JS上按日期范围过滤数据?

vba - 无法摆脱脚本中的硬编码延迟

python-3.x - 如何安装 Selenium