Selenium代码等待CSS类可用并在Python中提取文本 [英] Selenium code to wait until CSS class is available and extract text in Python

查看:120
本文介绍了Selenium代码等待CSS类可用并在Python中提取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在这里已经看过一些相关的问题,但是它们都与查找一个类然后提取属于该类的文本无关.

I have looked at some questions on here that are somewhat related but none of them are concerned with finding a class and then extracting text that is part of that class.

我的目标是使进入网站的过程自动化,该网站可以查找给定名称和域名的电子邮件.到目前为止,我已经有了用于自动输入名称和域的代码,然后单击搜索",但是我的问题是等待结果加载.我基本上希望我的代码能等到CSS类一个"出现后,再提取与此类相关的文本,例如以下代码段:

My goal is to automate the process of entry into a website that finds emails, given name and domain names. So far I have the code to automate the entry of the name and domain, and then click on "search", but my issue is waiting for a result to load. I basically want my code wot wait until the CSS class "one" is present and then extract the text related to this class, e.g. for the following snippet:

<h3 class="one">Success</h3>

提取文本成功".

推荐答案

您需要 明确等待以使元素可见:

You need to explicitly wait for the element to become visible:

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

wait = WebDriverWait(driver, 10)
h3 = wait.until(EC.visibility_of_element_located((By.CSS_SELECTOR, "h3.one")))
print h3.text

这篇关于Selenium代码等待CSS类可用并在Python中提取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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