Selenium RC getTitle 方法

发布于 2024-10-06 16:53:57 字数 1216 浏览 0 评论 0原文

已经过去很长一段时间了:-)

我仍在学习 Selenium RC,并且使用 www.irishtimes.com 作为我的测试应用程序。

我有一个非常小的测试用例,由以下步骤组成:

Selenium selenium;

public void setUp() throws Exception {
    super.setUp();

    selenium = new DefaultSelenium("localhost",
            SELENIUM_PORT,
            "*firefox",
            "http://www.irishtimes.com/");

    setUp("http://www.irishtimes.com/", "*firefox");
}
public void testTCNewspapers() throws Exception {
    selenium.start();
    selenium.open("http://www.irishtimes.com/");
    selenium.waitForPageToLoad("30000");
    selenium.click("link=Life");

    //Doesn't work
    //verifyEquals("The Irish Times - Life", sel.getTitle());

执行 verifyEquals 时,我收到此错误:

java.lang.AssertionError: java.lang.AssertionError: Expected "The Irish Times - Life" but saw "The Irish Times – Irish News, Business News, Sports News & Ireland Weather Online" instead

com.thoughtworks.selenium.SeleneseTestBase.fail(SeleneseTestBase.java:356)

我不明白为什么会发生这种情况,因为页面的标题是“爱尔兰时报 - Life”

来自源 html 文件:

<title>The Irish Times - Life</title>

对解决这个问题有什么帮助吗?谢谢 ;-)

it's been a long time :-)

I'm still with my learning of Selenium RC and I'm using the www.irishtimes.com as my tested application.

I have a very tiny test case that consists of these steps:

Selenium selenium;

public void setUp() throws Exception {
    super.setUp();

    selenium = new DefaultSelenium("localhost",
            SELENIUM_PORT,
            "*firefox",
            "http://www.irishtimes.com/");

    setUp("http://www.irishtimes.com/", "*firefox");
}
public void testTCNewspapers() throws Exception {
    selenium.start();
    selenium.open("http://www.irishtimes.com/");
    selenium.waitForPageToLoad("30000");
    selenium.click("link=Life");

    //Doesn't work
    //verifyEquals("The Irish Times - Life", sel.getTitle());

}

When executing the verifyEquals I'm getting this error:

java.lang.AssertionError: java.lang.AssertionError: Expected "The Irish Times - Life" but saw "The Irish Times – Irish News, Business News, Sports News & Ireland Weather Online" instead

at com.thoughtworks.selenium.SeleneseTestBase.fail(SeleneseTestBase.java:356)

I don't understand why this is happening since the title of the page is "The Irish Times - Life"

From the source html file:

<title>The Irish Times - Life</title>

Any help on resolving this? Thanks ;-)

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

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

发布评论

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

评论(3

雾里花 2024-10-13 16:53:57

Selenium 在发送“点击”后不会等待新页面加载。

尝试使用“clickAndWait” - 这应该会导致 Selenium 在继续之前等待服务器的响应。

Selenium doesn't wait for the new page to load after sending 'click'.

Try using 'clickAndWait' - that should cause Selenium to wait for a response from the server before continuing.

调妓 2024-10-13 16:53:57

您需要告诉 Selenium 等待页面加载。

请参阅此处: Selenium IDE:输入太“早”

You need to tell Selenium to wait for the page to load.

See here: Selenium IDE : Input too "early"

污味仙女 2024-10-13 16:53:57

我可以从源 html 文件中清楚地看到标题,
爱尔兰时报 – 爱尔兰新闻、商业新闻、体育新闻和爱尔兰天气在线我用chrome查看源码

I can clearly see the title from the source html file as,
The Irish Times – Irish News, Business News, Sports News & Ireland Weather Online I used chrome to view the source

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