Python Selenium正在单击超链接,但仍保留在同一页面上
我正试图使用selenium刮取一个javascript页面,但在点击时遇到了一些问题。点击不会转到另一个页面,而是使用javascript来显示接下来的十条评论,我想略过这十条评论 第一次单击似乎有效,但第二次单击不起作用,总是说没有元素存在 我使用的代码是Python Selenium正在单击超链接,但仍保留在同一页面上,python,selenium,click,Python,Selenium,Click,我正试图使用selenium刮取一个javascript页面,但在点击时遇到了一些问题。点击不会转到另一个页面,而是使用javascript来显示接下来的十条评论,我想略过这十条评论 第一次单击似乎有效,但第二次单击不起作用,总是说没有元素存在 我使用的代码是 from selenium import webdriver from selenium.webdriver.support.ui import WebDriverWait from selenium.common.exceptions
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By
browser = webdriver.Firefox()
browser.get("http://www.agoda.com/the-coast-resort-koh-phangan/hotel/koh-phangan-th.html")
delay = 3 # seconds
xpath = "//a[@id='next-page']"
try:
WebDriverWait(browser, delay).until(expected_conditions.element_to_be_clickable((By.XPATH, xpath)))
print "Page is ready!"
except TimeoutException:
print "Loading took too much time!"
browser.find_element_by_xpath("//a[@id='next-page']").click()
try:
WebDriverWait(browser, delay).until(expected_conditions.element_to_be_clickable((By.XPATH, xpath)))
print "Page is ready!"
except TimeoutException:
print "Loading took too much time!"
browser.find_element_by_xpath("//a[@id='next-page']").click()
try:
WebDriverWait(browser, delay).until(expected_conditions.element_to_be_clickable((By.XPATH, xpath)))
print "Page is ready!"
except TimeoutException:
print "Loading took too much time!"
给
Page is ready!
Page is ready!
WebDriverException: Message: Element is not clickable at point
我已经检查了要单击的元素是否在那里,是否知道这为什么不起作用
我不明白的是,它说页面已经准备好了,因此它找到了我试图点击的元素,但当我去点击这个元素时,它说该元素不可点击?这里我将把导航页面的代码放在我使用的Chrome驱动程序中: 您可以从这里下载:
硒试图在元素的中间单击,并且由于某种原因,看起来由于某些原因,元素在中间无法点击。它可以被找到,并且是可点击的,只是不在它试图点击的地方。元素可点击检查元素是否可见并已启用,但实际上不检查元素的中间部分本身是否可点击。也许可以尝试向下滚动页面,使箭头元素完全在视图中?有关此问题,请参阅stackoverflow帖子。
from selenium import webdriver
from selenium.webdriver.support.ui import WebDriverWait
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.common.by import By
import time
browser = webdriver.Chrome("./chromedriver.exe")
browser.get("http://www.agoda.com/the-coast-resort-koh-phangan/hotel/koh-phangan-th.html")
delay = 3 # seconds
xpath = "//a[@id='next-page']"
try:
for i in range(0,5):
browser.find_element_by_id("next-page").click()
time.sleep(5)
print i
except Exception as e:
print e
time.sleep(5)
browser.quit()