首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >如何使用JavaScript executor获取网页标题

如何使用JavaScript executor获取网页标题
EN

Stack Overflow用户
提问于 2018-01-02 18:52:29
回答 3查看 3.6K关注 0票数 0

我是自动化测试的新手。在我的代码中,我在Selenium自动化测试脚本(使用JUnit)上使用了JavaScript。我正在尝试查找当前窗口标题:

代码语言:javascript
复制
driver = new ChromeDriver();
js = (JavaScriptExecutor)driver;

driver.get(//passed url);

//after the log in my Org. I execute the command below

//to get the title of the current window I execute the below command        
js.executeScript("document.getElementsByTagName('title').innerHTML;"); 

,但上面的命令将返回作为获取窗口标题的瞬间的答案。有人知道我的命令出了什么问题吗?

但我在页面的控制台日志上获得了执行时窗口的标题。所以我不知道我的代码出了什么问题。

谢谢。

莫汉·拉杰·S。

EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/48059614

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档