Selenium:如何在Firefox Driver上设置移动模式

时间:2016-08-12 07:19:08

标签: selenium selenium-firefoxdriver firefox-profile

我参与了Selenium Firefox Driver with Java
我正在寻找移动模式。但它只是ChromeDriver的代码。 我知道我们会FirefoxProfile但我不会澄清java上的代码 如何为FirfoxDriver设置移动模式。 感谢

2 个答案:

答案 0 :(得分:2)

当然是chrome驱动程序的大多数资源
所以测试一下 对我有用

<!--sidebar left-->
<div id="mySidebarLeft" class="sidebarLeft">
  <a href="javascript:void(0)" class="closebtnLeft" onclick="closeNavLeft()">×</a>
</div>

<!--main card-->
<div id="main" class="card bg-light">
  <div class="pt-3">
    <div class="row pull-right">
      <div class="col-12 ">
        <ul class="flex-lg-row d-flex flex-column mb-0 p-0">
          <li class="d-inline px-lg-1">
            <button class="btn fas fa-arrow-left openbtn" onclick="openNavLeft()">
                                        </button>
            <button class="btn fas fa-arrow-right openbtn" onclick="openNavRight()"> 
                                        </button>
          </li>
        </ul>
      </div>
    </div>
    <div class="clearfix"></div>
  </div>
  <div class="card-block px-3 pb-0">
    <table id="example" class="table table-hover display responsive no-wrap" width="100%"></table>
  </div>
</div>

<!--sidebar right-->
<div id="mySidebarRight" class="sidebarRight">
  <a href="javascript:void(0)" class="closebtnRight" onclick="closeNavRight()">×</a>
</div>



<!-------------------------------- CDN's css-------------------------------------->

<!-- Bootstrap & fontawesome css -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
<link rel="stylesheet" href="https://pro.fontawesome.com/releases/v5.10.0/css/all.css" integrity="sha384-AYmEC3Yw5cVb3ZcuHtOA93w35dYTsvhLPVnYs9eStHfGJvOvKxVfELGroGkvsg+p" crossorigin="anonymous" />
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.21/css/dataTables.bootstrap4.min.css" />
<!-- Datatable css -->
<link rel="stylesheet" href="https://cdn.datatables.net/1.10.18/css/jquery.dataTables.min.css" />
<link rel="stylesheet" href="https://cdn.datatables.net/autofill/2.3.0/css/autoFill.dataTables.min.css" />
<link rel="stylesheet" href="https://cdn.datatables.net/fixedcolumns/3.2.5/css/fixedColumns.dataTables.min.css" />
<link rel="stylesheet" href="https://cdn.datatables.net/responsive/2.2.2/css/responsive.dataTables.min.css" />
<!-------------------------------- CDN's js-------------------------------------->
<!-- Boostrap & fontawesome js-->
<script src="https://code.jquery.com/jquery-3.5.1.slim.min.js" integrity="sha256-4+XzXVhsDmqanXGHaHvgh1gMQKX40OUvDEBTu8JcmNs=" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
<!-- Datatable js -->
<script type="text/javascript" src="https://cdn.datatables.net/1.10.18/js/jquery.dataTables.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/autofill/2.3.0/js/dataTables.autoFill.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/fixedcolumns/3.2.5/js/dataTables.fixedColumns.min.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/scroller/2.0.0/js/dataTables.scroller.js"></script>
<script type="text/javascript" src="https://cdn.datatables.net/responsive/2.2.2/js/dataTables.responsive.min.js"></script>

如果您愿意提供用户代理,这可以为您提供帮助

firefox_options.set_capability("deviceName", "iPhone")

如果您使用Java maby,则可以看到此python代码,此链接对此有帮助 https://stqatools.com/selenium-desired-capability-marionette/

答案 1 :(得分:1)

看看这是否适合你。

fprofile.setPreference("general.useragent.override", "iPhone");

或者您可以尝试其他问题中提到的内容 - How to use webdriver mobile web on desktop browser