【发布时间】:2020-07-28 21:47:43
【问题描述】:
是的,有类似的问题,但是在阅读它们后,我无法找到解决问题的方法。
以下情况:我正在尝试单击“https://charleston.craigslist.org/ctd/d/charleston-2018-nissan-sentra-sedan-4d/7108660907.html”上的“回复”按钮,执行此单击后会出现一个弹出窗口,我将在其中单击另一个按钮,但让我们从第一个按钮作为“回复”开始" 点击本身就很麻烦。
回复按钮的 X-Path 如下:
'/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))并尝试单击按钮,但这失败并且网站只是刷新 - 我的猜测是他们要么重新识别浏览器Selenium 控制,点击是不合法的,或者我在我的代码中没有捕捉到任何正确的东西。任何人都可以帮忙吗?
顺便说一句,我已经尝试过搜索“by_class_name”,但也没有用。
【问题讨论】:
标签: python selenium button click refresh