【问题标题】:Emulation in selenium with node not working在 selenium 中进行仿真,节点不工作
【发布时间】:2021-06-10 20:58:20
【问题描述】:

问题
这段代码应该在 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}`)
})

【问题讨论】:

    标签: javascript node.js selenium google-chrome selenium-webdriver


    【解决方案1】:
    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);
    

    https://www.selenium.dev/selenium/docs/api/javascript/module/selenium-webdriver/chrome_exports_Options.html

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2017-08-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-20
      • 2018-10-10
      • 2016-10-20
      • 2020-03-02
      相关资源
      最近更新 更多