使用硒单击并查看更多文本 [英] Use selenium to click and view more text

查看:76
本文介绍了使用硒单击并查看更多文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我对Selenium非常陌生. 我正在从此页面中抓取数据.我需要向下滚动页面,然后单击加载更多参数"以获取更多文本.这是要单击的位置.

I'm very new to Selenium. I'm crawling data from this page. I need to scroll down the page and click on "Load More Arguments" to get more text. This is the location to click on.

<a class="debate-more-btn" href="javascript:void(0);" onclick="loadMoreArguments('15F7E61D-89B8-443A-A21C-13FD5EAA6087');">
      Load More Arguments
</a>

我已经尝试过此代码,但是它不起作用.我是否需要更多代码来定位(我认为 1 已经告诉了要单击的位置).你有什么建议吗?先感谢您.

I have tried this code but it does not work. Should I need more code to locate to that (I think the 1 has already tell the location to click). Do you have any recommendation? Thank you in advance.

[1] btn_moreDebate = driver.find_elements_by_class_name("debate-more-btn")
[2] btn.click()

推荐答案

查找链接

Find the link by link text, move to the element and click:

from selenium.webdriver.common.action_chains import ActionChains

link = driver.find_element_by_link_text('Load More Arguments')
ActionChains(browser).move_to_element(link).perform()
link.click()

如果在查找元素时遇到异常,则可能需要使用明确等待:

If you get an exception while finding an element, you may need to use an Explicit Wait:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

link = WebDriverWait(driver, 10).until(EC.element_to_be_clickable((By.LINK_TEXT, "Load More Arguments")))
ActionChains(browser).move_to_element(link).perform()
link.click()

这篇关于使用硒单击并查看更多文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆