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

a 夏天 提交于 2019-12-24 09:58:47

问题


I have this html:

<div class="title">
<div class="subtitle">
<div id="flhcd1>
<h3>Hello</h3>
<span></span>
</div>
<div class="subtitle2">
</div>
</div>

I want to be able to use selenium and javascript to store the text in the <h3> (Hello) in the variable titleText .

I will be using this code in browsermob for monitoring tests.


回答1:


In BrowserMob you can do

var titleText = selenium.getText("//div[@id='flhcd']/h3");

and then use titleText like you would any variable.



来源:https://stackoverflow.com/questions/3740281/how-do-you-store-an-elements-text-with-selenium-in-a-javascript-variable

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!