Javascript 与Python&;Selenium(无法定位元素)

Javascript 与Python&;Selenium(无法定位元素),javascript,python,selenium,selenium-webdriver,Javascript,Python,Selenium,Selenium Webdriver,我一直在努力清理以下站点()。我想做的是单击“shots”,然后让javascript加载,然后将鼠标悬停在每个“shot元素”上,并提取出现的数据(时间和玩家信息) 我的问题是,当我试图将鼠标悬停在“快照元素”上时,会不断出现“无法定位元素”错误。当我在打印页面源代码时,我可以清楚地看到元素实际上就在那里,当我保存屏幕截图时也可以看到 我认为这些元素可能被隐藏起来了。我试着“切换到”(可能是错误的),但没有成功 driver = webdriver.Firefox(executable_pat

我一直在努力清理以下站点()。我想做的是单击“shots”,然后让javascript加载,然后将鼠标悬停在每个“shot元素”上,并提取出现的数据(时间和玩家信息)

我的问题是,当我试图将鼠标悬停在“快照元素”上时,会不断出现“无法定位元素”错误。当我在打印页面源代码时,我可以清楚地看到元素实际上就在那里,当我保存屏幕截图时也可以看到

我认为这些元素可能被隐藏起来了。我试着“切换到”(可能是错误的),但没有成功

driver = webdriver.Firefox(executable_path='/usr/bin/geckodriver')
driver.get("http://epl.squawka.com/english-premier-league/21-05-2017/watford-vs-man-city/matches")

try:
    element = WebDriverWait(driver, 1000).until(EC.element_to_be_clickable((By.XPATH,"//*[@id='mc-content-wrap']/div[2]/div[1]")))
finally:
    driver.find_element_by_xpath("//*[@id='mc-content-wrap']/div[2]/div[1]").click()

time.sleep(1)   
driver.find_element_by_id("mc-stat-shot").click()
time.sleep(5)   
shotsVar = -1
html = driver.page_source
bsObj = BeautifulSoup(html, "html.parser")
for circle in bsObj.find("svg",{'height':'224.6'}).findAll('circle'):
    shotsVar += 1
    if circle['r'] == '6.5':
        shotsXpathCode = ("//*[@id='mc-pitch-view']/div[2]/div[1]/svg/g[%s]/circle" % shotsVar)
        print(shotsXpathCode)
        try:
            element = WebDriverWait(driver, 100).until(EC.presence_of_element_located((By.XPATH,"%s" % shotsXpathCode)))
        finally:
            element_to_hover_over = driver.find_element_by_xpath("%s" % shotsXpathCode)
            hover = ActionChains(driver).move_to_element(element_to_hover_over)
            hover.perform()

Xpath和SVG似乎不能很好地协同工作

请尝试以下XPath:

"//*[@id='mc-pitch-view']/div[2]/div[1]/*[name()='svg']/*[name()='g'][%s]/*[name()='circle']"
相关的: