单击带有 id 的 DIV

我正在尝试让 selenium-webdriver 单击 ID 为“发送按钮”的 div


driver.findElement(By.xpath("//a[contains(text(),'Send anonymously')]")).click();

driver.findElement(By.id("send-button)).click();

(async function example() {

    let driver = await new Builder().forBrowser('firefox').build();

    try {

      await driver.get('https://onyolo.com/VFUF5VtxPJ');

      await driver.findElement(By.name('text')).sendKeys('test', Key.RETURN);

      await driver.findElement(By.xpath("//a[contains(text(),'Send anonymously')]")).click();

      await driver.wait(until.reload);

    } finally {

      await driver.quit();

    }

  })();

网站上的html代码


<div id="send-button">Send anonymously</div>


阿晨1998
浏览 126回答 2
2回答

Qyouu

您可以使用executeScript方法运行纯 javascript&nbsp;。await driver.executeScript(`document.getElementById('send-button').click()`);

aluckdog

您是否错过了提供正确的 xpath 的机会?您使用了“a”而不是“div”//div[contains(text(),'匿名发送')]
打开App,查看更多内容
随时随地看视频慕课网APP

相关分类

JavaScript