我正在使用selenium和Javascript。当我想点击一个元素时,我得到这个错误。我使用了显式等待,但它没有帮助。有人能帮助我吗?
这是test.js文件:
const Browser = require("../Browser")
const MainPage = require("../pageobjects/MainPage")
const AlertPage = require("../pageobjects/AlertPage");
describe("Test 1", function(){
it("test case", async function(){
await Browser.goToUrl("https://demoqa.com/")
let mainPage = new MainPage();
let isMainPageDisplayed = await mainPage.isMainPageDisplayed();
expect(isMainPageDisplayed).to.be.true
await mainPage.clickAlertFrameWindows()
let alertPage = new AlertPage()
let isAlertPageDisplayed = await alertPage.isAlertElDisplayed();
expect(isAlertPageDisplayed).to.be.true
await alertPage.clickAlertEl()
await Browser.closeBrowser()
})
})
AlertPage.js:
class AlertPage{
#name = "Alert Page";
#locator = "//span[text()='Alerts']"
#alertEl = new BaseElement(this.#locator, "Alert button")
clickAlertEl(){
BrowserFactory.getBrowser().wait(until.elementLocated(By.xpath("//span[text()='Alerts']/ancestor::li[contains(@class,'btn')]")))
this.#alertEl.clickWithExecutor()
}
isAlertElDisplayed(){
// BrowserFactory.getBrowser().wait(until.elementLocated(By.xpath("//span[text()='Alerts']/ancestor::li[contains(@class,'btn')]")))
return this.#alertEl.isElementPresent()
}
}
module.exports = AlertPage;
HTML快照:
1条答案
按热度按时间px9o7tmv1#
通常
<span>
标签更容易点击。因此在 *clickAlertEl()
* 中尝试:或者干脆