在学习过程中,遇到已下问题

问题一:

ChromeDriver error “unknown error: cannot get automation extension”

我用的chrome是70以上的版本,使用之前的chromedriver.exe时,报如上错误。

解决办法:很简单,更新chromedriver.exe版本

下载地址:https://sites.google.com/a/chromium.org/chromedriver/downloads

参考:https://stackoverflow.com/questions/42204586/chromedriver-error-unknown-error-cannot-get-automation-extension

问题二:比较坑爹。

如图:

Selenium:学习过程中遇到的坑集合

描述:这个登陆元素,根据F12,得到两个。可以通过document.getElementsByClassName(‘moco-btn moco-btn-red’)查看。这样就导致,点击的时候,不知道这是哪一个元素。

解决办法1:

List<WebElement> checkboxs = driver.findElements(By.className("ant-checkbox-input")); 

checkboxs.get(i).click();

缺点:后前端代码有改变,那么我需要重新定位在第几个

解决办法2:

List<WebElement> checkboxs = driver.findElements(By.className("ant-checkbox-input"));
        System.out.println("checkboxs num is " + checkboxs.size());
        for(int i=0; i <checkboxs.size(); i++){
            System.out.println(checkboxs.get(i).getAttribute("outerHTML"));
            try {
                checkboxs.get(i).click();
                break;
            } catch (ElementNotVisibleException e) {
                continue;
            }

        }

缺点:要确认第一次的点击就是我们需要目标元素
我暂时使用的时第一种方法,毕竟时可以动业务上去确定哪一个才是我需要的。
问题完美解决。

参考:https://blog.csdn.net/chyo098/article/details/78921556

相关文章:

  • 2021-10-14
  • 2022-01-20
  • 2022-01-22
  • 2021-11-21
  • 2021-11-01
  • 2021-10-23
  • 2021-04-26
猜你喜欢
  • 2021-08-24
  • 2021-10-12
  • 2021-05-23
  • 2021-12-22
  • 2022-12-23
  • 2021-09-11
  • 2021-05-09
相关资源
相似解决方案