我整天尝试使用不同的选择器(id,class和href)在自动化测试中按一个按钮,但我不能。使用ID更容易,但是我在youtube上进行练习,并且在第一次单击(在汉堡菜单上)后,之后再也无法按任何标签(历史记录,订阅,图书馆等)。
const { Given, When, Then } = require('cucumber'); const { Builder, By, Key, until } = require('selenium-webdriver'); const { expect, assert } = require('chai'); let driver = new Builder().forBrowser('chrome').build(); Given('Youtube', {timeout: 2 * 5000}, async function () { await driver.get('https://www.youtube.com/?gl=ES&hl=es'); }); When('Library', {timeout: 2 * 5000}, async function () { await driver.findElement(By.id("guide-icon")).click(); }); When('Notice', {timeout: 2 * 5000}, async function () { await driver.findElement(By.css("style-scope ytd-guide-entry-renderer")).click(); });
也尝试使用Xpath(我需要定位Web的特定部分,并且我有多个具有相同值的类)。
When('Notice', {timeout: 2 * 5000}, async function () { await driver.findElement(By.xpath("//a[@href='/feed/history']")).click(); });
该功能文件正常。
[每次运行测试时,我都会收到此消息
NoSuchElementError: no such element: Unable to locate element: {"method":"css selector","selector":"style-scope ytd-guide-entry-renderer"} (Session info: chrome=80.0.3987.132)
谢谢你们;)
我整天尝试使用不同的选择器(id,class和href)在自动化测试中按一个按钮,但我不能。使用ID更容易,但我会在youtube以及第一个...
对不起,我正在使用javascript写硒