我尝试使用findElement()
功能在我的网页中找到元素。但是我收到了以下错误 -
DevTools listening on ws://127.0.0.1:12127/devtools/browser/92800bba-de09-487a-93c4-61053590a4a2
(node:4944) UnhandledPromiseRejectionWarning: NoSuchElementError: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="captchaimg"]"}
之后我认为可能是因为异步执行方式,所以尝试使用wait()
函数,但错误仍然存在。
代码 -
var webdriver = require('selenium-webdriver');
var driver = new webdriver.Builder().withCapabilities(webdriver.Capabilities.chrome()).build();
driver.get("https://www.imsnsit.org/imsnsit/student.htm");
driver.wait(webdriver.until.elementLocated({xpath: '//*[@id="captchaimg"]'}));
var img = driver.findElement({xpath: '//*[@id="captchaimg"]'});
var link = img.getAttribute('src');
console.log(link);
提前致谢