zoukankan      html  css  js  c++  java
  • selenium除错

    1.使用命令行启动selenium

      下载selenium jar包  http://selenium-release.storage.googleapis.com/index.html

      此处下载的是selenium-server-standalone-3.13.0.jar

      java -jar selenium-server-standalone-3.13.0.jar

    2. 执行java脚本

    import org.apache.commons.io.FileUtils;
    import org.openqa.selenium.OutputType;
    import org.openqa.selenium.WebDriver;
    import org.openqa.selenium.chrome.ChromeOptions;
    import org.openqa.selenium.remote.DesiredCapabilities;
    import org.openqa.selenium.remote.RemoteWebDriver;
    import org.testng.TestNG;
    import org.testng.annotations.Test;

    import java.io.File;
    import java.io.IOException;
    import java.net.URL;
    import java.util.concurrent.TimeUnit;

    public class errrotTest {
    @Test
    public void chrome() throws IOException {
    DesiredCapabilities capabilities=new DesiredCapabilities();
    ChromeOptions chromeOptions=new ChromeOptions();
    //chromeOptions.addArguments("headless");
    //chromeOptions.addArguments("window-size=400,1024");
    //chromeOptions.addArguments("user-agent="Mozilla/5.0 (Linux; Android 4.4.2; Nexus 4 Build/KOT49H) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/34.0.1847.114 Mobile Safari/537.36"");
    capabilities.setCapability(ChromeOptions.CAPABILITY, chromeOptions);

    RemoteWebDriver driver=new RemoteWebDriver(new URL("http://127.0.0.1:5555/wd/hub"), capabilities);
    driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
    driver.get("http://www.baidu.com");
    FileUtils.copyFile(driver.getScreenshotAs(OutputType.FILE), new File("1.png"));
    }
    }

    3. 使用tcpdump查看报错信息

      注意:使用tcpdump生成是二进制文件

    sudo tcpdump -i any port 4444 -w tcpdump.log

    4. 使用em-proxy查看报错信息

    gem安装中会出现一些权限问题,需要用sudo安装。为了操作方便,以后要将ruby卸载,使用普通用户安装。

    gem install em-proxy

    em-proxy -l 5555 -r 127.0.0.1:4444 -v

    5. 脚本中没有写Chrome driver路径,脚本依然可以启动chrome浏览器,是因为path中已经添加chromedriver

  • 相关阅读:
    mysql 版本查看
    js 中文乱码
    浏览器内核
    Squid 代理服务器
    minicygwin
    firefox 插件开发
    ocx c++
    NetBeans
    android 虚拟机
    ExpandableListView
  • 原文地址:https://www.cnblogs.com/csj2018/p/9249947.html
Copyright © 2011-2022 走看看