【发布时间】:2021-11-03 05:52:31
【问题描述】:
我一直在尝试修复ElementClickInterceptedException,但我的方法不起作用。这是我正在使用的Link。当我在游戏时间之前单击左侧的栏时,它会打开一个类似于弹出窗口的东西,但它在同一个窗口中,如图所示...
我能够在页面上获得所需的信息。问题是我通过单击x 关闭它后,它不会循环到下一个,它给了我ElementClickInterceptedException: Message: Element is not clickable at point because another element obscures it。大多数情况下,它在第二个循环中执行此操作,但有时它会通过第二个循环并进入第三个循环,但它从未通过第三个循环。我尝试使用等待,直到,但这没有任何帮助,它只会转到Timeout。这是我正在使用的代码。
#This fetch all the games I want to scrape for into a list of selenium objects
v1 = _.find_elements_by_class_name('trOddsSection')
driver.implicitly_wait(10)
for __ in v1:
driver.implicitly_wait(10)
#__.find_element_by_class_name("col-0").click()
wait.until(EC.element_to_be_clickable((By.XPATH, ".//td[@class='col-0']")))
yyy = __.find_element_by_xpath(".//td[@class='col-0']")
# This click gets the pop-up thing out
yyy.click()
v3 = wait.until(EC.presence_of_element_located((By.CLASS_NAME, "divStatisticsWidget")))
sleep(3)
try:
driver.implicitly_wait(10)
# This is where I scrape what I want from the pop-up
a = v3.find_element_by_xpath(".//div[@id='right-container']/div[@id='content_headToHead']/div[@class='sectionFound']/div[@class='teamWinsDraws']")
hm = a.find_element_by_xpath(".//div[@class='teamHomeWins']/span[@class='teamName']/span[@class='resultsPerc']").text
dr = a.find_element_by_xpath(".//div[@class='teamDraws']/span[@class='teamName']/span[@class='resultsPerc']").text
aw = a.find_element_by_xpath(".//div[@class='teamAwayWins']/span[@class='teamName']/span[@class='resultsPerc']").text
print("Here:\t\t{}\t{}\t{}".format(hm, dr, aw))
driver.implicitly_wait(10)
a_ = v3.find_element_by_xpath(".//div[@id='right-container']/div[@id='content_headToHead']/div[@class='sectionFound']/div[@class='headToHeadHistory']")
a__ = a_.find_elements_by_xpath(".//table/tbody/tr/td[@class='score']")
print("H2H {}".format(a__[0].text))
except(NoSuchElementException):
print("teamWinDraws class not found")
# This is where I close the pop-up window so I can move to next
try:
driver.implicitly_wait(10)
sleep(4)
wait.until(EC.element_to_be_clickable((By.XPATH, ".//*[@class='close-icon']")))
g_g = driver.find_element_by_xpath(".//*[@class = 'close-icon']")
driver.execute_script("arguments[0].click();", g_g)
except(NoSuchElementException):
print('close-icon not found')
except(TimeoutException):
print('Timed out')
任何人看到我做错了什么或如何解决这个问题,请告诉我。
【问题讨论】:
标签: python python-3.x selenium web-scraping selenium-chromedriver