selenium 获取数据

发布时间 2024-01-04 17:11:47作者: 晨曦与晚霞之间
const {Builder, Browser, By, Key, until} = require('selenium-webdriver');
let aa = function(){
  (async function example() {
  let driver = await new Builder().forBrowser(Browser.CHROME).build();
  try {
    await driver.get('https://fanyi.baidu.com/');
   
    let click = driver.findElement(By.className("desktop-guide-close"));//获取元素
    const actions = driver.actions({async: true});//获取鼠标点击对象
    await actions.move({origin: click}).click().perform();//发送点击并放开操作

    await driver.findElement(By.id('baidu_translate_input')).sendKeys('apple', Key.RETURN);
    await driver.wait(until.titleIs('黑马程序员 - 百度搜索'), 1000);
  } finally {
    await driver.quit();    
  }
})();
}
aa()