我想在iFrame中找到一些元素(WYIWYG编辑器)。
我尝试了很多替代品,但所有这些都没有解决我的问题。 :/
你们中的任何人都可以提供帮助吗?我认为那里的实现有点问题,可能需要一些黑客或神奇的解决方案才能解决这个问题。
我的代码:
//node packages
const webdriver = require('selenium-webdriver');
const chrome = require('chromedriver');
const chai = require('chai');
//conf
let element_time = 10000;
let driver = new webdriver.Builder()
.forBrowser('chrome')
.setChromeOptions(/* ... */)
.build();
//classes
const actionSequence = webdriver.ActionSequence;
const key = webdriver.Key;
const By = webdriver.By;
const until = webdriver.until;
const expect = chai.expect;
//test cases
describe("Test", async function(){
this.timeout(30000);
before(function(){
driver.manage().window().maximize();
});
it("Step 1 - Heading to rm.com", async function(){
await driver.get('https://www.rt.com');
});
it("Step 2 - Heading into the main article", async function(){
try {
await driver.findElement(By.css('a.main-promobox__link')).click();
} finally {
return null;
}
});
it("Step 4 - Switching to iFrame and publishing the content", async function(){
try {
await driver.switchTo().frame(driver.findElement(By.css("div.sppre_frame-container>iframe")));
let userName = driver.findElement(By.xpath('//*[@id=\"root\"]/div/div[2]/div[2]/div[2]/div[1]/div[1]/input'));
let txtEditor = driver.findElement(By.className("ql-editor"));
await userName.click();
await userName.sendKeys("Idan");
await driver.actions(txtEditor).mouseMove().mouseUp().mouseDown().perform();
await txtEditor.sendKeys('Bla.. Bla.. Bla..' + "\n" + 'Bla.. Bla.. Bla..');
driver.sleep(2000);
} finally {
return null;
}
});
})
我想要达到的具体元素 -
错误:
Test
✓ Step 1 - Heading to rm.com (8159ms)
✓ Step 2 - Heading into the main article (10942ms)
(node:43961) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): NoSuchElementError: no such element: Unable to locate element: {"method":"css selector","selector":".ql-editor"}
(Session info: chrome=64.0.3282.186)
(Driver info: chromedriver=2.36.540469 (1881fd7f8641508feb5166b7cae561d87723cfa8),platform=Mac OS X 10.13.3 x86_64)
(node:43961) [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.
✓ Step 4 - Switching to iFrame and publishing the content (270ms)
技术信息 节点JS |摩卡