有没有办法将硒中某个元素中的文本存储在变量中?

发布于 2024-09-17 22:29:46 字数 452 浏览 2 评论 0原文

我有一个使用 Selenium IDE 创建的 selenium 脚本。我是 想知道是否有办法存储某个特定的文本 变量中的元素以便我稍后可以在脚本中使用该文本?我使用 selenium IDE 来完成此操作,然后将其导入 browsermob 中。

例如:我有这个html:

<div id=title>
     <h2>Website</h2>
     <h3><span>web app</span>www.google.com</h3>
</div>

h3(www.google.com)中的文本随着不同的页面而变化。我希望脚本能够在所有这些页面上运行,抓取 h3 中的文本(在本例中为 www.google.com),并将其存储在 javascript 变量中,我可以在脚本的后面部分使用该变量。

I have a selenium script that I created with Selenium IDE. I was
wondering if there is anyway to store the text that is in a certain
element in a variable so that I can use that text later in the script? I am using selenium IDE to do it and then importing it into browsermob.

For Example: I have this html:

<div id=title>
     <h2>Website</h2>
     <h3><span>web app</span>www.google.com</h3>
</div>

The text in the h3 (www.google.com) changes with different pages. I want a script to be able to run on all these pages that grabs the text in the h3 (in this case www.google.com), and stores it in a javascript variable which I can use in a later part of the script.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

焚却相思 2024-09-24 22:29:47

您可以使用以下代码来完成您的任务。它会起作用的。

storeEval window.document.getElementById('menuless') varname 
echo varname 

You can use the following piece of code for your task. It will work.

storeEval window.document.getElementById('menuless') varname 
echo varname 
简美 2024-09-24 22:29:46

http://seleniumhq.org/docs/04_selenese_commands.html# store-commands-and-selenium-variables

根据您想要执行的操作,storeEval 命令可能有用。您应该能够使用 // 作为 storeEval 命令的参数来启动 Xpath(以便 Selenium 知道您正在引用 Xpath,而不是 DOM 元素)。

http://seleniumhq.org/docs/04_selenese_commands.html#store-commands-and-selenium-variables

Depending what exactly you are trying to do, the storeEval command may be of use. You should just be able to start the Xpath with // as the argument to the storeEval command (so that Selenium knows that you are referencing an Xpath rather than, say, a DOM element).

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文