为什么不能点击Selenium中的元素? [英] Why Cant I Click an Element in Selenium?
本文介绍了为什么不能点击Selenium中的元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想点击Selenium中的一个元素。
I am trying to click an element in Selenium.
网站是:url = http://jenner.com / people
元素的xpath是:url = // div [@ class ='filter offices']
The xpath for the element is: url = //div[@class='filter offices']
这是我的代码:
from selenium import webdriver
driver = webdriver.Firefox()
driver.get(url)
element = driver.find_element_by_xpath("//div[@class='filter offices']")
element.click()
当我点击元素时,会出现办公室的下拉菜单。相反,当我单击该元素,什么也没有发生。
When I click the element, the drop down for offices should appear. Instead, when I click the element, nothing happens. What am I doing wrong?
推荐答案
您正在点击包含带有事件侦听器的其他div的div。您应该点击侦听器注册的div。这个xpath应该工作:
You are clicking on div that contains other div with event listener. You should click on div where listener ist registered. This xpath should work:
//div[@class='filter offices']/div[@class='header']
这篇关于为什么不能点击Selenium中的元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文