我正在为我的SpringBoot应用程序开发selenium测试,我已经设法创建了一个新帐户,在该帐户上创建了一个新项目,并给它的值为funds=0,然后我向该项目捐款,并重定向到显示用户贡献的页面,其中包括' amountcontribudelement ',其值为>
如何在Selenium测试中检查元素的值?我的尝试如下,我得到的错误如下:
//重定向到用户贡献页面。asserequals ("Your contribution " this.webDriver.getTitle());
//Assert that the total contributed amount for the project is 2000 as it was 0 prior to contribution.
assertEquals("2000", this.webDriver.findElement(By.id("amountContributed")));
expected: <2000> but was: <[[ChromeDriver: chrome on WINDOWS (60e2cb3895ae1f8e300b2068bd0f46c7)] -> id: amountContributed]>
HTML:
<span>Amount Contributed: </span>
<li th:text="${project.amountContributed}" id="amountContributed">Amount Contributed</li>
看这个
this.webDriver.findElement(By.id("amountContributed"))
将返回一个web元素,而你正在比较一个web元素。这就是你得到以下异常的原因:
预期:& lt; 2000比;而是:<[[ChromeDriver: WINDOWS上的chrome(60 e2cb3895ae1f8e300b2068bd0f46c7)→id: amountContributed]在
试试这个:
assertEquals("2000", this.webDriver.findElement(By.id("amountContributed")).getText());
但是你分享的HTML:
<span>Amount Contributed: </span>
<li th:text="${project.amountContributed}" id="amountContributed">Amount Contributed</li>
表示如果使用amountContributed
作为id,.getText()
将返回
Amount Contributed
字符串,断言将再次失败。