2013-05-12 15 views
5

Selenium에서 요소를 클릭하려고합니다.왜 Selenium에서 요소를 클릭 할 수 있습니까?

사이트는 다음 URL = "http://jenner.com/people는"요소의

는 XPath는 다음 URL = // DIV [클래스 @ = '필터 사무실']

다음

내 코드입니다 :

from selenium import webdriver 
driver = webdriver.Firefox() 
driver.get(url) 
element = driver.find_element_by_xpath("//div[@class='filter offices']") 
element.click() 

요소를 클릭하면 사무실에 대한 드롭 다운이 나타납니다. 대신, 요소를 클릭하면 아무 일도 일어나지 않습니다. 내가 도대체 ​​뭘 잘못하고있는 겁니까?

답변

4

다른 div가 포함 된 div를 이벤트 수신기로 클릭합니다. listener가 등록되지 않은 div를 클릭해야합니다. 이 XPath는 작동합니다 :

//div[@class='filter offices']/div[@class='header'] 
+0

'필터 오피스'가 들어있는 수신기가 아니라 자식 div에 수신기가 등록되어 있다는 것을 어떻게 알았습니까? – Mugen

+0

리스너 이벤트가 어디에 등록되어 있는지 어떻게 알 수 있습니까? – Floella

3

을 여기에, 나는 당신이 위치를 선택 스크립트를 작업을 제공합니다.

from selenium import webdriver 
import time 

driver = webdriver.Chrome('./chromedriver.exe') 
url="https://jenner.com/people" 
try: 
    driver.get(url) 
    element = driver.find_element_by_xpath("//div[@class='filter offices']") 
    element.click() 
    time.sleep(5) 
    element = driver.find_element_by_xpath("//input[@id='search_offices_chicago']") 
    element.click() 
    time.sleep(5) 
except Exception as e: 
    print e 
    driver.quit() 
driver.quit() 
관련 문제