javascript - 在 selenium 中进行仿真,节点不工作
问题描述
问题
此代码应该在 chrome 中打开移动仿真,但由于某种原因它不起作用我正在使用 Selenium 和 express。Chrome 可打开但未处于仿真模式且未出现错误
const express = require('express')
var webdriver = require('selenium-webdriver');
const app = express()
const port = 5000
var capabilities = {
browserName: 'chrome',
chromeOptions: {
mobileEmulation: {
deviceName: 'Apple iPhone 6'
}
}
};
async function google() {
var driver = await new webdriver
.Builder()
.withCapabilities(capabilities)
.build();
await driver.get('https://www.whatismybrowser.com/detect/what-is-my-user-agent')
}
app.get('/', (req, res) => {
google()
})
app.listen(port, () => {
console.log(`Example app listening at http://localhost:${port}`)
})
解决方案
var capabilities = {
browserName: 'chrome',
goo:chromeOptions: {
mobileEmulation: {
deviceName: 'Apple iPhone 6'
}
}
};
你应该使用 goo:chromeOptions https://chromedriver.storage.googleapis.com/2.31/notes.txt
您还可以将 chrome 选项用作:
let options = new chrome.Options().setMobileEmulation(
{deviceName: 'Google Nexus 5'});
let driver = chrome.Driver.createSession(options);
推荐阅读
- sip - 有没有办法检索 rtpproxy 分配的会话?
- c# - 我无法扫描 Maxicode Barcode Zxing Xamarin
- azure - 文件共享未显示为服务,尽管它说配置提供了它
- c - 避免在部分代码中调用 sigchld 处理程序
- docker - docker 上的 ElasticSearch 集群
- python-3.x - 使用 Python 3.7.3,如何禁用 Tkinter 的背景“Tab”键绑定
- angular - 在 Angular 项目中找不到 node_modules 文件夹
- javascript - 重新加载页面后,颜色选择器和罢工(两者)将如何保留?
- python - Python ldap3 Reader 只返回一个值
- neo4j - 在一个查询中创建多个连接