【问题标题】:Selenium JavaScript Clicking in a Dropdown MenuSelenium JavaScript 单击下拉菜单
【发布时间】:2019-04-18 21:53:06
【问题描述】:

下面的代码转到一个页面,找到下拉菜单并单击列表中的第一个。如何调整以下代码以便能够选择列表中的第二项或第三项?

await browser
       .findElement(By.css('#historyTabDropdown ul>li>a'))
       .then(e => e.click());

【问题讨论】:

    标签: javascript selenium google-chrome browser automation


    【解决方案1】:

    尝试使用 css 选择器 nth-child。 css 是 li:nth-child(2)

    await browser
           .findElement(By.css('#historyTabDropdown ul>li:nth-child(2)>a'))
           .then(e => e.click());
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-11-12
      • 2023-04-09
      • 1970-01-01
      • 2012-09-05
      • 1970-01-01
      • 1970-01-01
      • 2018-07-07
      • 1970-01-01
      相关资源
      最近更新 更多