简体   繁体   English

无法使用phantomjs python单击Selenium Webdriver中的元素

[英]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.

相关问题 无法使用python和selenium连接到phantomJs webdriver - Trouble connecting to phantomJs webdriver using python and selenium Python Selenium PhantomJS没有单击Firefox Webdriver能够单击的相同按钮 - Python Selenium PhantomJS not clicking on same button that Firefox Webdriver is able to click 为什么不能使用python和Chrome Webdriver单击Selenium中的一个元素? - Why Cant I Click an Element in Selenium using python and Chrome Webdriver? 使用 Python 和 selenium webdriver 单击没有 ID/名称的按钮元素 - Click on button element without id/name using Python and selenium webdriver 在phantomjs中使用代理(Selenium WebDriver) - Using a proxy with phantomjs (selenium webdriver) 如何在 selenium webdriver python 中点击以下元素 - How to click the below element in selenium webdriver python 元素未在Odoo中单击python selenium webdriver中的单击 - Element is not clicking on click in python selenium webdriver in Odoo Selenium Webdriver (Python) - 单击 div 元素(复选框) - Selenium Webdriver (Python) - Click on a div element (checkbox) 找到Python Selenium Webdriver元素,但无法单击它 - Python Selenium Webdriver element found but can not click on it 如何在python中使用phantomjs和selenium webdriver设置窗口大小 - How to set window size using phantomjs and selenium webdriver in python
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM