Search code examples
seleniumselenium-webdriverselenium-iedriver

I am writing a selenium script and i am not able to write the xpath for the below code


I am writing a selenium script and i am not able to write the xpath for the below code

<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>

I tried the below script and there is success i need to find the text that is appearing within Success notification.

//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


Solution

  • Use the xptah:

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

    Hope that it helps.