如何处理,元素点击被拦截,其他元素在Selenium Python中会收到点击错误?

时间:2019-04-30 09:50:55

标签: python selenium web-scraping automation

这是我的代码:

wait.until(ec.element_to_be_clickable((By.CSS_SELECTOR, "[class='hotels-review-list-parts-LanguageFilter__row_label--26g7t']")))
language_options = driver.find_elements_by_css_selector("[class='hotels-review-list-parts-LanguageFilter__row_label--26g7t']")
for i in language_options:
     if i.find_element_by_css_selector("span.hotels-review-list-parts-LanguageFilter__no_wrap--3zMxR").text == "All languages":
         try:
             print("Getting Elemant into View | Method: 1")
             coordinates = i.location_once_scrolled_into_view
             driver.execute_script('window.scrollTo({}, {});'.format(coordinates['x'], coordinates['y']))
             i.click()
             break
         except:
             try:
                 print("Getting Elemant into View | Method: 2")
                 ActionChains(driver).move_to_element(i).perform()
                 i.click()
                 break
             except:
                 print("Getting Elemant into View | Method: 3")
                 driver.execute_script("arguments[0].scrollIntoView();", i)
                 i.click()
                 break

有时工作正常,但有时会出错

  

ElementClickInterceptedException('截获元素点击:元素...在点(656、16)不可点击。其他元素将获得点击。')

可能无法正常工作的原因是导致上述三种方法失败的原因是什么?

0 个答案:

没有答案