Java 我们可以使用Selenium或任何其他JAR来获得网络响应和验证吗
这里我有一个要求,我需要使用selenium和java验证网络响应值 如果有任何代码可以帮助我,那就太好了 我想要执行的操作(需要自动化)是Java 我们可以使用Selenium或任何其他JAR来获得网络响应和验证吗,java,selenium-webdriver,querystringparameter,Java,Selenium Webdriver,Querystringparameter,这里我有一个要求,我需要使用selenium和java验证网络响应值 如果有任何代码可以帮助我,那就太好了 我想要执行的操作(需要自动化)是 加载应用程序 加载应用程序时,按F12并转到网络选项卡 选择包含b/S的相应网络 单击它并获取查询参数中的值 我在下图中突出显示了它们 注意:我需要为应用程序加载后发生的每个单击事件执行此操作 这在硒中可能吗 这是我试图获取记录值的代码。我做得对吗?请帮助 public static void main(String[] args) throws IO
public static void main(String[] args) throws IOException {
System.setProperty("webdriver.chrome.driver",
new File(".").getCanonicalPath() + "\\WebDriver\\chromedriver.exe");
WebDriver driver = new ChromeDriver();
driver.get("https://www.ancestry.com");
//capture(driver);
driver.quit();
}
public static void capture(WebDriver driver) throws IOException {
OutputStream logfile = new FileOutputStream(new File(new
File(".").getCanonicalPath() + "\\log.txt"), true);
PrintStream printlog = new PrintStream(logfile);
LogEntries logs = driver.manage().logs().get(LogType.PERFORMANCE);
for (LogEntry entry : logs) {
if (entry.toString().contains("\"type\":\"Img\""))
System.out.println(entry.toString());
printlog.append(new Date(entry.getTimestamp()) + " " + entry.toString() + " "
+ System.getProperty("line.separator"));
printlog.append(System.getProperty("line.separator"));
printlog.append(System.getProperty("line.separator"));
}
printlog.close();
}
我们可以使用浏览器移动代理获取所有网络日志
private static BrowserMobProxy proxy = new BrowserMobProxyServer();
public webLib(String browser) {
logReport.logMethodStart("Launch Application");
Proxy seleniumProxy = null;
proxy.start();
seleniumProxy = ClientUtil.createSeleniumProxy(proxy);
if (browser.equalsIgnoreCase("chrome")) {
try {
System.setProperty("webdriver.chrome.driver",
new File(".").getCanonicalFile() + seperator + "WebDriver" + seperator + "chromeDriver.exe");
} catch (IOException e) {
e.printStackTrace();
}
ChromeOptions options = new ChromeOptions();
options.setCapability(CapabilityType.PROXY, seleniumProxy);
options.setAcceptInsecureCerts(true);
options.addArguments("--ignore-certificate-errors");
options.addArguments("--disable-popup-blocking");
options.addArguments("--no-sandbox");
options.addArguments("--no-sandbox");
driver = new ChromeDriver(options);
} else if (browser.equalsIgnoreCase("firefox")) {
}
driver.manage().deleteAllCookies();
driver.manage().window().maximize();
driver.manage().timeouts().pageLoadTimeout(20, TimeUnit.SECONDS);
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
if (driver != null) {
logReport.logStep(Status.PASS, "Browser launched successfully", driver);
}
}
您可以参照以下站点
你好,Siyadh,欢迎来到StackOverflow。请包括您迄今为止尝试的内容,通读并相应更新您的问题。感谢您的指导Brydenr将添加详细信息