[英]Selenium WebDriverJS from Javascript API
苦苦挣扎,同时理解WebDriverJS并承诺......大多数示例代码都是针对Python / Java而不是Javascript。 我所要做的就是获取页面的完整html。 因此,如果您查看WebDriverJS的相同代码:
var webdriver = require('selenium-webdriver');
...
driver.get('http://www.google.com');
driver.findElement(webdriver.By.name('q')).sendKeys('webdriver');
driver.findElement(webdriver.By.name('btnG')).click();
driver.wait(function() {
return driver.getTitle().then(function(title) {
return title === 'webdriver - Google Search';
});
}, 1000);
我试图简单地返回整个html文档而不仅仅是标题。 在Python中,它是driver.page_source。 我从例子中学得更好,所以我在这里有点沮丧。
我通常更喜欢在文档不清楚的情况下探索源代码。
这是包含相关getPageSource()
函数的主webdriver.js
源代码 :
/**
* Schedules a command to retrieve the current page's source. The page source
* returned is a representation of the underlying DOM: do not expect it to be
* formatted or escaped in the same way as the response sent from the web
* server.
* @return {!webdriver.promise.Promise.<string>} A promise that will be
* resolved with the current page source.
*/
webdriver.WebDriver.prototype.getPageSource = function() {
return this.schedule(
new webdriver.Command(webdriver.CommandName.GET_PAGE_SOURCE),
'WebDriver.getAllWindowHandles()');
};
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.