我正在写一个selenium脚本,我无法为下面的代码编写xpath

时间:2016-10-17 16:03:16

标签: selenium selenium-webdriver selenium-iedriver

我正在写一个selenium脚本,我无法为下面的代码编写xpath

<div id="notification">
<div class="success">
Success: You have added
 <a href="http://10.207.182.108:81/opencart/index.php?route=product/product&amp;product_id=28">HTC Touch HD</a> to your
 <a href="http://10.207.182.108:81/opencart/index.php?route=checkout/cart">
shopping cart</a>!<img class="close" alt="" src="catalog/view/theme/default/image/close.png"></div></div>

我尝试了下面的脚本并且成功了,我需要找到成功通知中出现的文本。

//Add 1st Products
    driver.findElement(By.xpath("//input[contains(@onclick, '28')]")).click();
    String msg = driver.findElement (By.xpath("//div[@id='notification']/div")).getText();
    String expectedmsg="Success: You have added HTC Touch HD to your shopping cart!";
    Assert.assertEquals(msg, expectedmsg);

THe highlighted one is the xpath i need

1 个答案:

答案 0 :(得分:1)

使用xptah:

//div[@id='notification']/div[@class='success']

希望它有所帮助。