我定义了WebDriver,转到示例页面:http://webscraper.io/test-sites/e-commerce/more/computers/tablets,然后单击" LoadMore"按钮好几次。它们都不起作用。
这是我使用它的方式(在scala中,如果你愿意,我可以用Java翻译和测试):
val baseCaps = new DesiredCapabilities
baseCaps.setCapability(CapabilityType.SUPPORTS_FINDING_BY_CSS, true)
baseCaps.setCapability("takesScreenshot", true)
baseCaps.setCapability(PhantomJSDriverService.PHANTOMJS_EXECUTABLE_PATH_PROPERTY, <my binary path>)
val driver = new PhantomJSDriver(baseCaps)
driver.get("http://webscraper.io/test-sites/e-commerce/more/computers/tablets")
val wait = new WebDriverWait(driver, 10)
val element = wait.until(ExpectedConditions.elementToBeClickable(By.cssSelector(selector)))
element.click()
<wait for a few seconds>
val page = driver.getPageSource.getBytes("UTF8")
PageSource显示在点击
之前它仍然是页面