开发者

Is there a way to store in a variable the text in a certain element in selenium?

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:开发者_Go百科 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.


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).


see How do you store an elements text with selenium in a javascript variable?


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜