Fix build for selenium upgrading from 3.141.59 to 4.14.1, refs #1134.
parent
e4ab6e27e4
commit
22a60df6aa
|
@ -1,15 +1,5 @@
|
||||||
package us.codecraft.webmagic.downloader.selenium;
|
package us.codecraft.webmagic.downloader.selenium;
|
||||||
|
|
||||||
import org.openqa.selenium.WebDriver;
|
|
||||||
import org.openqa.selenium.chrome.ChromeDriver;
|
|
||||||
import org.openqa.selenium.firefox.FirefoxDriver;
|
|
||||||
import org.openqa.selenium.phantomjs.PhantomJSDriver;
|
|
||||||
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
|
|
||||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
|
||||||
import org.openqa.selenium.remote.RemoteWebDriver;
|
|
||||||
import org.slf4j.Logger;
|
|
||||||
import org.slf4j.LoggerFactory;
|
|
||||||
|
|
||||||
import java.io.FileReader;
|
import java.io.FileReader;
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
import java.net.MalformedURLException;
|
import java.net.MalformedURLException;
|
||||||
|
@ -22,6 +12,18 @@ import java.util.concurrent.BlockingDeque;
|
||||||
import java.util.concurrent.LinkedBlockingDeque;
|
import java.util.concurrent.LinkedBlockingDeque;
|
||||||
import java.util.concurrent.atomic.AtomicInteger;
|
import java.util.concurrent.atomic.AtomicInteger;
|
||||||
|
|
||||||
|
import org.openqa.selenium.WebDriver;
|
||||||
|
import org.openqa.selenium.chrome.ChromeDriver;
|
||||||
|
import org.openqa.selenium.chrome.ChromeOptions;
|
||||||
|
import org.openqa.selenium.firefox.FirefoxDriver;
|
||||||
|
import org.openqa.selenium.firefox.FirefoxOptions;
|
||||||
|
import org.openqa.selenium.phantomjs.PhantomJSDriver;
|
||||||
|
import org.openqa.selenium.phantomjs.PhantomJSDriverService;
|
||||||
|
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||||
|
import org.openqa.selenium.remote.RemoteWebDriver;
|
||||||
|
import org.slf4j.Logger;
|
||||||
|
import org.slf4j.LoggerFactory;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author code4crafter@gmail.com <br>
|
* @author code4crafter@gmail.com <br>
|
||||||
* Date: 13-7-26 <br>
|
* Date: 13-7-26 <br>
|
||||||
|
@ -58,7 +60,7 @@ class WebDriverPool {
|
||||||
* Configure the GhostDriver, and initialize a WebDriver instance. This part
|
* Configure the GhostDriver, and initialize a WebDriver instance. This part
|
||||||
* of code comes from GhostDriver.
|
* of code comes from GhostDriver.
|
||||||
* https://github.com/detro/ghostdriver/tree/master/test/java/src/test/java/ghostdriver
|
* https://github.com/detro/ghostdriver/tree/master/test/java/src/test/java/ghostdriver
|
||||||
*
|
*
|
||||||
* @author bob.li.0718@gmail.com
|
* @author bob.li.0718@gmail.com
|
||||||
* @throws IOException
|
* @throws IOException
|
||||||
*/
|
*/
|
||||||
|
@ -73,7 +75,6 @@ class WebDriverPool {
|
||||||
|
|
||||||
// Prepare capabilities
|
// Prepare capabilities
|
||||||
sCaps = new DesiredCapabilities();
|
sCaps = new DesiredCapabilities();
|
||||||
sCaps.setJavascriptEnabled(true);
|
|
||||||
sCaps.setCapability("takesScreenshot", false);
|
sCaps.setCapability("takesScreenshot", false);
|
||||||
|
|
||||||
String driver = sConfig.getProperty("driver", DRIVER_PHANTOMJS);
|
String driver = sConfig.getProperty("driver", DRIVER_PHANTOMJS);
|
||||||
|
@ -134,9 +135,9 @@ class WebDriverPool {
|
||||||
sCaps.setBrowserName("phantomjs");
|
sCaps.setBrowserName("phantomjs");
|
||||||
mDriver = new RemoteWebDriver(new URL(driver), sCaps);
|
mDriver = new RemoteWebDriver(new URL(driver), sCaps);
|
||||||
} else if (driver.equals(DRIVER_FIREFOX)) {
|
} else if (driver.equals(DRIVER_FIREFOX)) {
|
||||||
mDriver = new FirefoxDriver(sCaps);
|
mDriver = new FirefoxDriver(new FirefoxOptions(sCaps));
|
||||||
} else if (driver.equals(DRIVER_CHROME)) {
|
} else if (driver.equals(DRIVER_CHROME)) {
|
||||||
mDriver = new ChromeDriver(sCaps);
|
mDriver = new ChromeDriver(new ChromeOptions().merge(sCaps));
|
||||||
} else if (driver.equals(DRIVER_PHANTOMJS)) {
|
} else if (driver.equals(DRIVER_PHANTOMJS)) {
|
||||||
mDriver = new PhantomJSDriver(sCaps);
|
mDriver = new PhantomJSDriver(sCaps);
|
||||||
}
|
}
|
||||||
|
@ -144,7 +145,7 @@ class WebDriverPool {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check whether input is a valid URL
|
* check whether input is a valid URL
|
||||||
*
|
*
|
||||||
* @author bob.li.0718@gmail.com
|
* @author bob.li.0718@gmail.com
|
||||||
* @param urlString urlString
|
* @param urlString urlString
|
||||||
* @return true means yes, otherwise no.
|
* @return true means yes, otherwise no.
|
||||||
|
@ -178,7 +179,7 @@ class WebDriverPool {
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
*
|
*
|
||||||
* @return
|
* @return
|
||||||
* @throws InterruptedException
|
* @throws InterruptedException
|
||||||
*/
|
*/
|
||||||
|
|
|
@ -1,17 +1,18 @@
|
||||||
package us.codecraft.webmagic.downloader;
|
package us.codecraft.webmagic.downloader;
|
||||||
|
|
||||||
|
import java.util.Arrays;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Ignore;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.openqa.selenium.By;
|
import org.openqa.selenium.By;
|
||||||
import org.openqa.selenium.WebDriver;
|
import org.openqa.selenium.WebDriver;
|
||||||
import org.openqa.selenium.WebElement;
|
import org.openqa.selenium.WebElement;
|
||||||
import org.openqa.selenium.chrome.ChromeDriver;
|
import org.openqa.selenium.chrome.ChromeDriver;
|
||||||
|
import org.openqa.selenium.chrome.ChromeOptions;
|
||||||
import org.openqa.selenium.remote.DesiredCapabilities;
|
import org.openqa.selenium.remote.DesiredCapabilities;
|
||||||
|
|
||||||
import java.util.Arrays;
|
|
||||||
import java.util.HashMap;
|
|
||||||
import java.util.Map;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author code4crafter@gmail.com <br>
|
* @author code4crafter@gmail.com <br>
|
||||||
* Date: 13-7-26 <br>
|
* Date: 13-7-26 <br>
|
||||||
|
@ -29,10 +30,10 @@ public class SeleniumTest {
|
||||||
Map<String, Object> preferences = new HashMap<String, Object>();
|
Map<String, Object> preferences = new HashMap<String, Object>();
|
||||||
preferences.put("profile.default_content_settings", contentSettings);
|
preferences.put("profile.default_content_settings", contentSettings);
|
||||||
|
|
||||||
DesiredCapabilities caps = DesiredCapabilities.chrome();
|
DesiredCapabilities caps = new DesiredCapabilities();
|
||||||
caps.setCapability("chrome.prefs", preferences);
|
caps.setCapability("chrome.prefs", preferences);
|
||||||
caps.setCapability("chrome.switches", Arrays.asList("--user-data-dir=/Users/yihua/temp/chrome"));
|
caps.setCapability("chrome.switches", Arrays.asList("--user-data-dir=/Users/yihua/temp/chrome"));
|
||||||
WebDriver webDriver = new ChromeDriver(caps);
|
WebDriver webDriver = new ChromeDriver(new ChromeOptions().merge(caps));
|
||||||
webDriver.get("http://huaban.com/");
|
webDriver.get("http://huaban.com/");
|
||||||
WebElement webElement = webDriver.findElement(By.xpath("/html"));
|
WebElement webElement = webDriver.findElement(By.xpath("/html"));
|
||||||
System.out.println(webElement.getAttribute("outerHTML"));
|
System.out.println(webElement.getAttribute("outerHTML"));
|
||||||
|
|
Loading…
Reference in New Issue