如何在 Python 中使用 Selenium WebDriver 获取文本 [英] How to get text with Selenium WebDriver in Python

查看:89
本文介绍了如何在 Python 中使用 Selenium WebDriver 获取文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试使用 Selenium WebDriver 获取文本,这是我的代码.请注意,我不想使用 XPath,因为在我的情况下,每次重新启动网页时 ID 都会更改.

I'm trying to get text using Selenium WebDriver and here is my code. Please note that I don't want to use XPath, because in my case the ID gets changed on every relaunch of the web page.

我的代码:

text = driver.find_element_by_class_name("current-stage").getText("my text")

HTML:

<span class="current-text" id="yui_3_7_0_4_1389185744113_384">my text</span>

我该如何解决这个问题?

How can I fix this?

推荐答案

您只需要 .text.

然后您可以在之后验证它,不要试图传递您期望它应该具有的东西.

You can then verify it after you've got it, don't attempt to pass in what you expect it should have.

这篇关于如何在 Python 中使用 Selenium WebDriver 获取文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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