[英]unnable to click element in selenium webdriver using phantomjs python
I've been using phantomjs along with selenium's webdriver in order to parse a page off it's information. 我一直在使用phantomjs和selenium的webdriver来解析信息页面。 The problem is in order to keep parsing I need to click the next button since the information is javascript generated, I've used the following lines
问题是为了继续解析,我需要单击下一步按钮,因为该信息是由javascript生成的,因此我使用了以下几行
next_page = browser.find_element_by_xpath("/descendant::a[@title='Siguiente'][1]")
webdriver.ActionChains(browser).move_to_element(next_page).click()
in the following context (url is actual parsed page) 在以下上下文中(URL是实际分析的页面)
from selenium import webdriver
PHANTOMJS_PATH = './phantomjs/phantomjs'
FARMACIA_URL = 'http://www.chedraui.com.mx/index.php/ajusco/endeca/category/view/id/457/'
browser = webdriver.PhantomJS(PHANTOMJS_PATH)
browser.get(FARMACIA_URL)
I have not gotten an error from the xpath not existing or any other error, the page simply does not refresh inside the program when clicked. 我没有从xpath不存在或其他任何错误中得到错误,单击时页面根本不会在程序内刷新。
I have tried using browser.implicitly_wait(4) before and after the action and substituting the click() method with send_keys("\\n") . 我尝试在操作前后使用browser.implicitly_wait(4)并用send_keys(“ \\ n”)代替click()方法。 There seem to be some more elaborated solutions involving javascript events but I have yet to try them and I'm a bit tired.
似乎还有一些涉及javascript事件的详细解决方案,但我还没有尝试过,我有点累。
Any clues as to why this behavior is happening and how to fix it are much appreciated. 非常感谢您提供任何有关为什么会发生此行为以及如何解决此问题的线索。
Thank you. 谢谢。
您需要在ActionChains
函数上调用perform()
ActionChains(browser).move_to_element(next_page).click().perform()
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.