七苦、 2021-10-21 17:57 采纳率: 0%
浏览 51
已结题

python + selenium 能定位出来算你厉害

img


常规定位元素方法基本上都试过了,定位不到。各位看看还有什么方法能进行元素定位

from tkinter import Image
import ddt
import unittest2
from upl.webUtil import *
#
import pytesseract
from PIL import Image
from PIL import Image, ImageEnhance
import os
import time
@ddt.ddt()
class UPL_Test(unittest2.TestCase):
    def setUp(self) -> None:
        self.driver = WebDriverUtil(path='chromedriver.exe')
        self.driver.get("http://192.168.59.122/user/login")
        self.driver.read("xpath.json")

    @ddt.file_data("data.json")
    def test(self, login):
        # 登录
        self.login(login)
        #音视频管理
        self.video()
    def login(self, login):
        self.driver.section = "login"
        # 进入登录页面
        # self.driver.get(login["url"])
        # 用户名输入
        self.driver.find_element("name").send_keys(login["name"])
        # 密码输入
        self.driver.find_element("password").send_keys(login["password"])
        # 获取验证码
        self.driver.find_element("code").send_keys(login["code"])#yzm()
        # 点击登录按钮
        self.driver.driver.implicitly_wait(5)
        self.driver.find_element("button").click()
    def video(self):
        self.driver.section="video"
        time.sleep(2)
        #点击节目单管理
        self.driver.find_element("programme").click()
        #新增
        self.driver.find_element("p_add").click()
        time.sleep(10)

if __name__ == '__main__':
    unittest2.main()

xpath.json

{
 "login": {
    "name": {
      "type": "id",
      "value": "username"
    },
   "password": {
     "type":"id",
     "value": "password"
   },
   "code": {
     "type": "id",
     "value": "inputCode"
   },
   "button": {
     "type": "xpath",
     "value": "//*[@id='formLogin']/div[2]/div/div/span/button"
   },
   "code_image": {
     "type": "xpath",
     "value": "//form[@id='formLogin']/div[1]/div[3]/div/div[4]/div[2]/img"
   }
 },
  "video": {
    "programme": {
     "type": "xpath",
     "value": "//*[@id='app']/section/aside/div/ul/li[9]/ul/li[2]/a/span"
   },
    "p_add": {
      "type": "xpath",
      "value": "//*[@id='app']/section/section/main/div[2]/div/div/div/div[2]/button"
    }
  }
}
  • 写回答

2条回答 默认 最新

  • Lavender丨 2021-10-25 15:31
    关注

    文本来定位?

    评论

报告相同问题?

问题事件

  • 已结题 (查看结题原因) 3月15日
  • 创建了问题 10月21日

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?