const webdriver = require('selenium-webdriver'); const {By} = webdriver; const {until: {expectedConditions: EC}} = webdriver; const {ActionSequence} = require('selenium-webdriver/lib/input'); const url = 'https://peterwang_f1WpCS:exzzsQRc8r2VS94frdZ1@hub-cloud.browserstack.com/wd/hub';

(async function example() { const driver = new webdriver.Builder() .usingServer(url) .withCapabilities(webdriver.Capabilities.chrome()) .build();

try { await driver.get('https://www.google.com');

const searchBox = await driver.findElement(By.name('q'));
await searchBox.sendKeys('BrowserStack', webdriver.Key.RETURN);
await driver.wait(EC.titleContains('BrowserStack'), 5000);

const link = await driver.findElement(By.css('.r a'));
await link.click();
await driver.wait(EC.urlContains('browserstack.com'), 5000);

const trialButton = await driver.findElement(By.linkText('Start Free Trial'));
await trialButton.click();
await driver.wait(EC.urlContains('register'), 5000);

const emailInput = await driver.findElement(By.id('user_email_login'));
const passwordInput = await driver.findElement(By.id('user_password'));
const submitButton = await driver.findElement(By.name('commit'));

await emailInput.sendKeys('test@example.com');
await passwordInput.sendKeys('password');
await submitButton.click();
await driver.wait(EC.urlContains('dashboard'), 5000);

const accountLink = await driver.findElement(By.id('account-menu-toggle'));
const planLink = await driver.findElement(By.linkText('Change plan'));

const actionSequence = new ActionSequence(driver);
await actionSequence.mouseMove(accountLink).click().mouseMove(planLink).click().perform();
await driver.wait(EC.urlContains('upgrade'), 5000);

} finally { await driver.quit(); } })();

用node重写以下代码:nimport-timenfrom-selenium-import-webdrivernimport-seleniumwebdriversupportexpected_conditions--as-ECnfrom-seleniumwebdriver-import-ActionChainsnfrom-seleniumwebdrivercommonby-import-Bynnimport-osnURL=httpspeterwang_f1WpCSexzzsQRc8r2VS94f

原文地址: https://www.cveoy.top/t/topic/rqH 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录