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

  • 相关阅读:
    sublime text 3安装 package control 插件的方法
    mysql 库和表占用空间查询
    错误:编码GBK的不可映射字符
    新系统设置 github 私钥
    git 之忽略文件 gitignore 创建和使用规则
    DesiredCapabilities内容详解(摘)
    appium-python自动化之get_attribute笔记(摘)
    excel批量插入图片-方法(宏和纯手工操作)
    利用Python将多个excel文件合并为一个文件
    notePad++ 运行python
  • 原文地址:https://www.cnblogs.com/csj2018/p/9249947.html
Copyright © 2011-2022 走看看