Selenium Click JS Button-Python?

问题描述 投票:1回答:1

是的,也有类似的问题,但是通读它们后,我无法找到解决问题的方法。

以下情况:我正在尝试单击“ https://charleston.craigslist.org/ctd/d/charleston-2018-nissan-sentra-sedan-4d/7108660907.html”上的“答复”按钮,执行此单击后,会弹出一个弹出窗口,在该窗口中,我将单击另一个按钮,但让我们从第一个按钮作为“答复”开始点击本身很麻烦。

回复按钮具有以下X路径:

'/html/body/section/section/header/div[2]/div/button'

谈到源代码是:

<button role="button" class="reply-button js-only" data-href="/__SERVICE_ID__/chs/ctd/7108660907">
      reply
    </button> 

((请参阅提到的网站上的代码)。

但是,我使用Selenium(Python)的方法不起作用:

reply_button = '/html/body/section/section/header/div[2]/div/button'
driver.get('https://charleston.craigslist.org/ctd/d/charleston-2018-nissan-sentra-sedan-4d/7108660907.html')

driver.find_element_by_xpath(reply_button).click()

[我每次尝试,网站都会正确加载(即使执行了time.sleep(x)),然后尝试单击按钮,但这失败了,网站只是刷新了-我的猜测是,他们要么重新定位了浏览器,就是硒-控制,则该点击是非法的,或者我没有在代码中正确捕获任何内容。有人能帮忙吗?

顺便说一句,我已经尝试过搜索“ by_class_name”,那也不起作用。

python selenium button click refresh
1个回答
0
投票
© www.soinside.com 2019 - 2024. All rights reserved.