我几乎尝试了SO线程中关于我的问题的所有技巧,但没有任何效果...我在youtube上观看了一些提示,但找不到答案...无处...
这是我的代码,很简单。这些步骤是: 1)登录页面 2)输入只有一个iFrame的页面 3)在一些输入中输入一些文本 4)输入iFrame,输入一些文字,然后返回文档 5)点击提交按钮发送表格。
尝试单击“提交”按钮时,它表示“提交”按钮不可见。
以下是我的代码和错误日志:
const url = 'home_page_url';
const addUrl = 'url_with_one_iframe_accesible_after_login';
const webdriver = require('selenium-webdriver');
let driver = new webdriver.Builder().forBrowser('chrome').build();
driver.manage().window().maximize();
driver.get(url);
const loginLink = driver.wait(webdriver.until.elementLocated({ xpath:'//*[@id="login-box"]/div/a' }));
loginLink.click().then(function () {
driver.wait(webdriver.until.elementLocated({ xpath: '//*[@id="edit-login-id"]'})).sendKeys('login@login.com');
driver.wait(webdriver.until.elementLocated({ xpath: '//*[@id="edit-login-password"]' })).sendKeys('pass');
loginButton = driver.wait(webdriver.until.elementLocated( { xpath: '//*[@id="edit-submit--7"]'} )).click(); // login to CGO main page
}).then(function () {
driver.wait(webdriver.until.elementLocated({ xpath: '//*[@id="admin-menu-account"]/li[1]' })).then(function () {
driver.get(addUrl);
driver.wait(webdriver.until.titleIs('Create Noticia | CitizenGO'));
driver.wait(webdriver.until.elementLocated({ xpath: '//*[@id="edit-title"]' })).sendKeys('new selenium notica title xpath');
driver.wait(webdriver.until.elementLocated({ xpath: '//*[@id="edit-field-topic-und"]/option[7]' })).click();
driver.switchTo().frame(driver.findElement({ xpath: '//*[@id="edit-body-und-0-value_ifr"]' })); // enter frame by ID
driver.wait(webdriver.until.elementLocated({ xpath: '//*[@id="tinymce"]'} )).sendKeys('just selenium-created notica xpath');
driver.switchTo().defaultContent();
}).then(function () {
driver.findElement(webdriver.By.id('edit-submit')).click();
});
});
控制台日志...
(node:12724) UnhandledPromiseRejectionWarning: StaleElementReferenceError: stale element reference: element is not attached to the page document
(Session info: chrome=77.0.3865.120)
at Object.throwDecodedError (C:\projekty\selenium-sandbox\node_modules\selenium-webdriver\lib\error.js:550:15)
at parseHttpResponse (C:\projekty\selenium-sandbox\node_modules\selenium-webdriver\lib\http.js:563:13)
at Executor.execute (C:\projekty\selenium-sandbox\node_modules\selenium-webdriver\lib\http.js:489:26)
at processTicksAndRejections (internal/process/task_queues.js:93:5)
at async thenableWebDriverProxy.execute (C:\projekty\selenium-sandbox\node_modules\selenium-webdriver\lib\webdriver.js:699:17)
(node:12724) 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(). (rejection id: 1)
(node:12724) [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.
我尝试了xpaths,没有,也有很多其他情况,这是我第一次感到如此沮丧!非常感谢您的帮助。