【问题标题】:I am writing a selenium script and i am not able to write the xpath for the below code我正在编写一个 selenium 脚本,但我无法为以下代码编写 xpath
【发布时间】:2016-10-17 16:03:16
【问题描述】:

我正在编写一个 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

【问题讨论】:

    标签: selenium selenium-webdriver selenium-iedriver


    【解决方案1】:

    使用 xptah:

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

    希望对你有帮助。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2015-10-17
      • 2022-11-25
      • 1970-01-01
      • 1970-01-01
      • 2014-06-23
      • 2021-03-07
      • 2010-09-05
      • 2020-02-14
      相关资源
      最近更新 更多