Selenium - Webdriver 关系图
image.pngSelenium1.0 javascript库 结构
image.pngFireFox
image.pngFirefoxDriver.prototype.getElementAttribute =函数(响应,参数){
var element = Utils.getElementAt(parameters.id,
response.session.getDocument());
var attributeName = parameters.name;
response.value = webdriver.element.getAttribute(element,attributeName);
response.send();
};
IE 驱动程序
image.pngSelenium Core
image.pngchromedriver
Chromedriver 最后调用的是chrome的api,下面是一段 等待页面加载完成的代码
Status ChromeDesktopImpl::WaitForPageToLoad(
const std::string& url,
const base::TimeDelta& timeout_raw,
std::unique_ptr<WebView>* web_view,
bool w3c_compliant) {
Timeout timeout(timeout_raw);
std::string id;
WebViewInfo::Type type = WebViewInfo::Type::kPage;
while (timeout.GetRemainingTime() > base::TimeDelta()) {
WebViewsInfo views_info;
Status status = devtools_http_client_->GetWebViewsInfo(&views_info); // 开发者工具
if (status.IsError())
return status;
for (size_t i = 0; i < views_info.GetSize(); ++i) {
const WebViewInfo& view_info = views_info.Get(i);
if (base::StartsWith(view_info.url, url, base::CompareCase::SENSITIVE)) {
id = view_info.id;
type = view_info.type;
break;
}
}
if (!id.empty())
break;
base::PlatformThread::Sleep(base::TimeDelta::FromMilliseconds(100));
}
if (id.empty())
return Status(kUnknownError, "page could not be found: " + url);
const DeviceMetrics* device_metrics = devtools_http_client_->device_metrics();
if (type == WebViewInfo::Type::kApp ||
type == WebViewInfo::Type::kBackgroundPage) {
// Apps and extensions don't work on Android, so it doesn't make sense to
// provide override device metrics in mobile emulation mode, and can also
// potentially crash the renderer, for more details see:
// https://code.google.com/p/chromedriver/issues/detail?id=1205
device_metrics = nullptr;
}
网友评论