@Test
public void testPhantomjs() throws GoogleValidationException{
String proxy = "station3:808";
String userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1";
org.openqa.selenium.Proxy p = new org.openqa.selenium.Proxy();
p.setHttpProxy(proxy).setFtpProxy(proxy).setSslProxy(proxy);
DesiredCapabilities capability = new DesiredCapabilities();
capability.setCapability(CapabilityType.PROXY, p);
capability.setJavascriptEnabled(true);
capability.setCapability("phantomjs.page.settings.userAgent",userAgent);
capability.setPlatform(Platform.WINDOWS);
capability.setVersion("40.1");
((DesiredCapabilities) capability).setJavascriptEnabled(true);
((DesiredCapabilities) capability).setCapability("takesScreenshot", true);
((DesiredCapabilities) capability).setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
"src/main/resources/phantomjs/phantomjs.exe"
);
PhantomJSDriver driver = new PhantomJSDriver(capability);
driver.get("https://www.google.com/imghp?hl=en&tab=wi");
driver.findElement(By.xpath(".//span[contains(@id,'qbi')]")).click();
driver.findElement(By.xpath(".//a[contains(@class,'qbtbha qbtbtxt qbclr')]")).click();
log.info(driver.getTitle());
driver.executePhantomJS("var page = this; page.uploadFile('input[id=qbfile]', 'D:/MediaUploadRoot/20150827/th.jpg');");
log.info(driver.getTitle());
(new WebDriverWait(driver, 60)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//img[contains(@class,'_u6')]")));
log.info(driver.getTitle());
List<WebElement> webElements = driver.findElements(By.xpath(".//a[contains(@class,'_gUb')]"));
for (WebElement webElement : webElements) {
String googleTag = GoogleTranslateUtils.translateToEnglish(webElement.getText());
List<String> tagList = NLPUtil.getTagsForSentence(googleTag);
log.info("NLPUtil---------------------->tagList: "+tagList);
}
}
public void testPhantomjs() throws GoogleValidationException{
String proxy = "station3:808";
String userAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:40.0) Gecko/20100101 Firefox/40.1";
org.openqa.selenium.Proxy p = new org.openqa.selenium.Proxy();
p.setHttpProxy(proxy).setFtpProxy(proxy).setSslProxy(proxy);
DesiredCapabilities capability = new DesiredCapabilities();
capability.setCapability(CapabilityType.PROXY, p);
capability.setJavascriptEnabled(true);
capability.setCapability("phantomjs.page.settings.userAgent",userAgent);
capability.setPlatform(Platform.WINDOWS);
capability.setVersion("40.1");
((DesiredCapabilities) capability).setJavascriptEnabled(true);
((DesiredCapabilities) capability).setCapability("takesScreenshot", true);
((DesiredCapabilities) capability).setCapability(
PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY,
"src/main/resources/phantomjs/phantomjs.exe"
);
PhantomJSDriver driver = new PhantomJSDriver(capability);
driver.get("https://www.google.com/imghp?hl=en&tab=wi");
driver.findElement(By.xpath(".//span[contains(@id,'qbi')]")).click();
driver.findElement(By.xpath(".//a[contains(@class,'qbtbha qbtbtxt qbclr')]")).click();
log.info(driver.getTitle());
driver.executePhantomJS("var page = this; page.uploadFile('input[id=qbfile]', 'D:/MediaUploadRoot/20150827/th.jpg');");
log.info(driver.getTitle());
(new WebDriverWait(driver, 60)).until(ExpectedConditions.visibilityOfElementLocated(By.xpath(".//img[contains(@class,'_u6')]")));
log.info(driver.getTitle());
List<WebElement> webElements = driver.findElements(By.xpath(".//a[contains(@class,'_gUb')]"));
for (WebElement webElement : webElements) {
String googleTag = GoogleTranslateUtils.translateToEnglish(webElement.getText());
List<String> tagList = NLPUtil.getTagsForSentence(googleTag);
log.info("NLPUtil---------------------->tagList: "+tagList);
}
}