我遇到的问题

  1. 获取到 登录按钮 的 xpath,且可以保证 xpath 正确无误
  2. 点击 登录按钮, 无法正常跳转到 登录成功页
from selenium import webdriver
from selenium.webdriver.chrome.options import Optionsmobile_emulation = {"deviceName": "iPhone X"}
options = Options()
options.add_experimental_option("mobileEmulation", mobile_emulation)
driver = webdriver.Chrome(chrome_options=options)
driver.get("https://xxx.com")
#输入帐号密码
driver.find_element_by_xpath("//*[@id='email-login-input']/div/div[2]/input").send_keys("user")
driver.find_element_by_xpath("/html/body/div/div/div[2]/div[2]/div[2]/div[4]/div/div/div[2]/input").send_keys("password")
#点击登录按钮
driver.find_element_by_xpath("/html/body/div/div/div[2]/div[2]/div[2]/button").click()
#点击后,无任何反应
  1. 触摸 登录按钮, 无法正常跳转到 登录成功页
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
from selenium.webdriver.common.touch_actions import TouchActionsmobile_emulation = {"deviceName": "iPhone X"}
options = Options()
options.add_experimental_option("mobileEmulation", mobile_emulation)
driver = webdriver.Chrome(chrome_options=options)
driver.get("https://xxx.com")
#输入帐号密码
driver.find_element_by_xpath("//*[@id='email-login-input']/div/div[2]/input").send_keys("user")
driver.find_element_by_xpath("/html/body/div/div/div[2]/div[2]/div[2]/div[4]/div/div/div[2]/input").send_keys("password")
#单次触摸 登录按钮
Action = TouchActions(driver)
loginButton = driver.find_element_by_xpath("/html/body/div/div/div[2]/div[2]/div[2]/button")
Action.tap(loginButton)
Action.perform()
#触摸后,有触摸的反馈,但仍无法跳转到 登录成功页
  1. 使用简单粗暴的方法send_keys(Keys.ENTER),模拟点击 回车键,可正常登录
from selenium import webdriver
from selenium.webdriver.chrome.options import Options
import time
from selenium.webdriver.common.keys import Keysmobile_emulation = {"deviceName": "iPhone X"}
options = Options()
options.add_experimental_option("mobileEmulation", mobile_emulation)
driver = webdriver.Chrome(chrome_options=options)
driver.get("https://xxx.com")
#输入帐号密码
driver.find_element_by_xpath("//*[@id='email-login-input']/div/div[2]/input").send_keys("user")
driver.find_element_by_xpath("/html/body/div/div/div[2]/div[2]/div[2]/div[4]/div/div/div[2]/input").send_keys("password")
#定位“登录按钮”,按“回车键”
loginButton = driver.find_element_by_xpath("/html/body/div/div/div[2]/div[2]/div[2]/button")
loginButton.send_keys(Keys.ENTER)
#点击 “回车键” 后,可正常跳转到 登录成功页,问题解决

webdriver 的Keys()类提供键盘上所有按键的操作

from selenium.webdriver.common.keys import Keys
#在使用键盘按键方法前需要先导入keys 类包。
#下面经常使用到的键盘操作:
send_keys(Keys.BACK_SPACE) #删除键(BackSpace)
send_keys(Keys.SPACE) #空格键(Space)
send_keys(Keys.TAB) #制表键(Tab)
send_keys(Keys.ESCAPE) #回退键(Esc)
send_keys(Keys.ENTER) #回车键(Enter)
send_keys(Keys.CONTROL,'a') #全选(Ctrl+A)
send_keys(Keys.CONTROL,'c') #复制(Ctrl+C)

selenium 模拟手机浏览器操作 click点击/tap触摸 元素无效 的解决方法相关推荐

  1. python 模拟手机浏览器_python+chrome+Selenium模拟手机浏览器

    环境 安装chrome,F12后有个模拟手机浏览器的功能,如果找不到就自己google下啊 下载chromedriver.exe,并放到python的根目录下 实现代码 不废话,直接码起来~ #引入必 ...

  2. selenium模拟手机浏览器测试

    selenium不仅仅可以测试桌面pc web浏览器,还可以对手机浏览器进行测试,从而不必用appium对手机测试,采用selenium比移动自动化有无可比拟的速度.稳定性优势: 学习目标:学会移动浏 ...

  3. python+Selenium自动化操作Chrome模拟手机浏览器

    在使用Chrome浏览网页时,我们可以使用Chrome开发者工具模拟手机浏览器,在使用Selenium操作Chrome时同样也可以模拟手机浏览器.主要有以下两种用途. 测试H5页面在不同分辨率设备上的 ...

  4. Python selenium —— 用chrome的Mobile emulation模拟手机浏览器测试手机网页

    很多人发现chrome有项功能,就是在开发者工具里能够模拟手机打开网页,便想能否用selenium对此进行自动化测试.答案当然是yes! 今天博主便给大家分享下如何用chrome的MobileEmul ...

  5. python 浏览器模拟手机_Python selenium —— 用chrome的Mobile emulation模拟手机浏览器测试手机网页...

    很多人发现chrome有项功能,就是在开发者工具里能够模拟手机打开网页,便想能否用selenium对此进行自动化测试.答案当然是yes! chrome-emulation 今天博主便给大家分享下如何用 ...

  6. python模拟手机操作_Selenium使用Chrome模拟手机浏览器方法解析

    在使用Chrome浏览网页时,我们可以使用Chrome开发者工具模拟手机浏览器,在使用Selenium操作Chrome时同样也可以模拟手机浏览器.主要有以下两种用途. 测试H5页面在不同分辨率设备上的 ...

  7. selenium之用chrome的Mobile emulation模拟手机浏览器测试手机网页

    很多人发现chrome有项功能,就是在开发者工具里能够模拟手机打开网页,便想能否用selenium对此进行自动化测试.答案当然是yes! 今天博主便给大家分享下如何用chrome的MobileEmul ...

  8. 【selenium】绕过selenium检测及模拟手机浏览器

    1.Chrome 版本小于88 web = Chrome() # 在启动浏览器之前添加这段js代码即可 web.execute_cdp_cmd("Page.addScriptToEvalua ...

  9. python获取登录按钮_Python:Selenium模拟Chrome浏览器抓取淘宝商品信息

    对于采用异步加载技术的网页,有时候想通过逆向工程的方式来设计爬虫进行爬取会比较困难,因此,要想通过python获取异步加载数据往往可以使用Selenium模拟浏览器的方式来获取. Selenium是一 ...

最新文章

  1. 【Java Web开发指南】解析Spring中Ioc和DI(入门Demo)
  2. axios请求五种方法
  3. android glide本地图片,Glide下载图片并保存到本地
  4. python菜单栏_pyqt5——菜单和工具栏
  5. 如何找到一篇论文的源代码?
  6. 如何远程访问Jetson Xavier/TX2
  7. 现在大家都使用支付宝和微信支付,为何银行还准备大量的现金?
  8. mysql 查看索引
  9. 基于AI的网易UI自动化测试方案与实践
  10. go语言 html 5 gui,仅需简单 5 步,给你的 Golang 程序添加 GUI (使用 Electron )
  11. 题解 P2146 【[NOI2015]软件包管理器】
  12. java关键字匹配算法_简单关键词匹配算法
  13. java sniffer_用Java来实现的Sniffer
  14. 笔记本电脑开机没画面/黑屏没反应怎么办?
  15. 【MATLAB】求解矩阵方程
  16. 计算广告——introduction
  17. Lossless CNN Channel Pruning via Decoupling Remembering and Forgetting
  18. 【笔记】2022.5.9 网页数据收集
  19. 软件开发团队中的特殊角色
  20. 如何远程办公 远程办公操作指南 7款好用的远程办公软件

热门文章

  1. 苏仪数据分析软件 更新 Analys1.2.2 2007/12/27
  2. 使用vue搭建多页面多系统应用
  3. 微服务架构搭建(JAVA)
  4. UE特效--Spline蓝图--制作数字城市道路分析
  5. nVisual综合布线可视化管理系统解决方案
  6. docker images处理
  7. 服务器型号T400,联想万全服务器T400-1002服务器上安装操作系统.doc
  8. 苹果手机解压缩软件_奇客派 篇六十一:压缩速度贼快,macOS又有一款好用的解压缩软件_软件应用...
  9. 我大学期间开发的所有网站
  10. gmapping.launch