炖白菜 2017-10-16 08:33 采纳率: 0%
浏览 3081

用selenium 的 xpath定位元素,为什么没报错但却没有去点击呢?

def setUp(self):
    self.url = "https://m.baidu.com/sf?top=%7B%22sfhs%22%3A1%7D&anchor=0811&pd=pl&word=%E8%87%AA%E7%94%B1%E4%BE%A0"
    options = webdriver.ChromeOptions()
    mobileEmulation = {'deviceName': 'Galaxy Note 3'}
    options.add_experimental_option('mobileEmulation', mobileEmulation)
    self.driver = webdriver.Chrome(executable_path='chromedriver.exe', chrome_options=options)
    self.driver.implicitly_wait(10)  #最多等待10秒,隐性等待对整个driver的周期都起作用,所以一次启动只要设置一次即可
    self.driver.get(self.url)
    self.assertTrue(ec.title_is(u"自由侠"))
    self.assertTrue(ec.visibility_of_element_located(u"自由侠"))

def tearDown(self):
    self.driver.quit()

def testCase1(self):
    locator = self.driver.find_element_by_xpath('//span[contains(text(), "7寸液晶仪表")]')
    locator.click()
  • 写回答

1条回答 默认 最新

  • jijindechandao 2019-09-18 23:36
    关注

    没有找到这个元素所以没点击,可能该页面有多个你要找的元素

    评论

报告相同问题?

悬赏问题

  • ¥15 请教一下各位,为什么我这个没有实现模拟点击
  • ¥15 执行 virtuoso 命令后,界面没有,cadence 启动不起来
  • ¥50 comfyui下连接animatediff节点生成视频质量非常差的原因
  • ¥20 有关区间dp的问题求解
  • ¥15 多电路系统共用电源的串扰问题
  • ¥15 slam rangenet++配置
  • ¥15 有没有研究水声通信方面的帮我改俩matlab代码
  • ¥15 ubuntu子系统密码忘记
  • ¥15 保护模式-系统加载-段寄存器
  • ¥15 电脑桌面设定一个区域禁止鼠标操作