使用selenium和Java测试HTML代码 [英] Test HTML code using selenium with Java

查看:99
本文介绍了使用selenium和Java测试HTML代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我不知道如何在java中编写代码来测试HTML代码。

I am not sure how I can write code in java to test HTML code.

我必须在HTML页面上匹配多个字符串。我的HTML页面看起来像

I have to match several strings on HTML page. My HTML page looks like

name: xyzfoo
standard: 5
division: C

但所有这些都是硬编码的

But all this is hardcoded in

<tr>... 
</tr>

,并且不与任何元素ID关联。所以,我不知道如何测试,如果字符串,我用硒与Java期待一个相匹配。

and not associated with any element id. So I am not sure how to test if string matches with the one that I am expecting by using selenium with Java.

推荐答案

使用硒的 webdriver的可以使用XPath或CSS选择器来定位的元素。此时,您可以检索所需元素中的文本,并将其与您自己的文本进行比较。

Using Selenium's WebDriver you can use a XPath or CSS selector to locate an element. At this point you can retrieve the text in the desired element and compare it with your own.

如果您要关闭测试路径并使用Visual Studio / Microsoft产品那么你可能要阅读了关于一但编码的UI测试的。这只是一个选择,因为那里有替代测试软件包。

If you are going down the testing path and are using Visual Studio/Microsoft Products then you may want to read up a but on Coded UI Tests. This is just one option as there are alternative testing packages out there.

这篇关于使用selenium和Java测试HTML代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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