Я начинаю с селена, у меня была проблема с селеном, который не может найти отображаемый элемент после того, как я выбрал 2 предыдущих элемента.
Это мой код:
driver.get('http://live.demoguru99.com/index.php/mobile.html');
driver.manage().window().maximize();
it("Click ‘Add to Compare’ of SONY XPERIA: ", function () {
driver.executeScript('window.scrollTo(0, 500);');
driver.findElement(webdriver.By.xpath('//*[@id="top"]/body/div/div/div[2]/div/div[2]/div[1]/div[3]/ul/li[1]/div/div[3]/ul/li[2]/a')).click();
});
it("Click ‘Add to Compare’ of IPHONE: ", function () {
driver.getAllWindowHandles().then(function(handles){
driver.switchTo().window(handles[0]).then(function(){
let result = driver.getTitle();
result.then(function(){
driver.executeScript('window.scrollTo(0, 500);');
driver.findElement(webdriver.By.xpath('//*[@id="top"]/body/div/div/div[2]/div/div[2]/div[1]/div[3]/ul/li[2]/div/div[3]/ul/li[2]/a')).click();
// Fail this step
driver.findElement(webdriver.By.xpath('//*[@id="top"]/body/div/div/div[2]/div/div[2]/div[3]/div[1]/div[2]/div/button/span/span')).click();
});
});
});
});
Это журнал ошибок:
DevTools listening on ws://127.0.0.1:59612/devtools/browser/e60cb75e-606d-4d0f-afc6-dd3d0c5b5965 [14840:7772:0503/233743.775:ERROR:browser_switcher_service.cc(238)] XXX Init() (node:4460) UnhandledPromiseRejectionWarning: NoSuchElementError: no such element: Unable to locate element: {"method":"xpath","selector":"//*[@id="top"]/body/div/div/div[2]/div/div[2]/div[3]/div[1]/div[2]/div/button/span/span"} (Session info: chrome=81.0.4044.129)
at Object.throwDecodedError (E:\AutomationTest\node_modules\selenium-webdriver\lib\error.js:550:15)
at parseHttpResponse (E:\AutomationTest\node_modules\selenium-webdriver\lib\http.js:565:13)
at Executor.execute (E:\AutomationTest\node_modules\selenium-webdriver\lib\http.js:491:26)
at processTicksAndRejections (internal/process/task_queues.js:97:5)
at async thenableWebDriverProxy.execute (E:\AutomationTest\node_modules\selenium-webdriver\lib\webdriver.js:700:17)
at async toWireValue (E:\AutomationTest\node_modules\selenium-webdriver\lib\webdriver.js:139:15)
at async E:\AutomationTest\node_modules\selenium-webdriver\lib\webdriver.js:190:16
at async forEachKey (E:\AutomationTest\node_modules\selenium-webdriver\lib\webdriver.js:184:9)
at async convertKeys (E:\AutomationTest\node_modules\selenium-webdriver\lib\webdriver.js:189:3)
at async thenableWebDriverProxy.execute (E:\AutomationTest\node_modules\selenium-webdriver\lib\webdriver.js:698:22)
(node:4460) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 1) (node:4460) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
Что не так в этом случае?