-1
在java中運行phantomjs讓我頭疼。當我運行程序和getpagesource時,我能夠提取a-> src屬性的ul-> li文本,但不能在SPAN標籤內。這可能是由於掩蓋或不正確的CSS。 JS腳本是角度的。selenium phantomjs span標籤不顯示
我選擇控制檯輸出後,我打電話driver.getPageSource()是(通知物業地址爲空):
<div class="propertylist-property-details col-lg-6">
<a href="/property-detail/gblhrdlad152749">
<span class="property-name ng-binding" ng-bind="data.AddressLine1"></span>
<span class="property-address ng-binding" ng-bind="data.AddressLine2"></span>
</a>
<!-- ngIf: -->
<span class="property-bullets">
<ul>
<li>- Grade II listed facade </li>
<li>- Exposed concrete beams </li>
<li>- Italian kitchens </li>
<li>- Underfloor heating and comfort cooling </li>
<li>1054 Sq.Feet (97.92 Sq.Metres) </li>
</ul>
</span>
</div>
我的Java代碼如下:
public static synchronized void testPhantomDriver() throws Exception {
DesiredCapabilities caps = new DesiredCapabilities();
caps.setJavascriptEnabled(true);
caps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, "C:\\location of \\phantomjs.exe");
String oldpage=""; String newpage="";
WebDriver driver = new PhantomJSDriver(caps);
try{
driver.get("http://search.savills.com/property-detail/gbcsrdlad140551#/r/list/property-for-sale%252Fengland%252Fbristol%252Fbristol%252Fbs1%252Fgbp");
WebElement menu = driver.findElement(By.xpath("//*[@id=\"ctl_GRS_PT_ND\"]")); // the trigger event element
Actions build = new Actions(driver); // ActionBuider
build.moveToElement(menu).build().perform(); // perform hover mouse over the needed element to triger visibility
build.click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
String pageSource = driver.getPageSource();
driver.findElement(By.id("ViewAll")).click();
driver.manage().timeouts().implicitlyWait(30, TimeUnit.SECONDS);
System.out.println("clicked");
//driver = scrollToBottom(driver, 2000);
try{
System.out.println("waiting");
driver.wait(4000);
}catch(InterruptedException ie){
System.out.println("iexception: " + ie);
}
System.out.println(driver.getPageSource());
}catch(Exception exp){
System.out.println("exception:" + exp);
driver.close();
driver.quit();
}
driver.close();
driver.quit();
}
/**
* Main method
*/
public static void main(String[] args) {
try {
// run webdriver
testPhantomDriver();
} catch (Exception ex) {
System.out.println("exception");
}
}
一些解決方案,我有一直在想你可能會幫忙? (1)加載iframe(2)或等待完成頁面加載。我嘗試使用connect(url).get()在Jsoup中讀取頁面,但隱藏的可見性仍然存在。
任何幫助,將不勝感激。