在Selenium Webdriver中提取隐藏的元素文本

时间:2016-12-01 18:20:51

标签: java selenium selenium-webdriver

我想使用Java在Selenium Webdriver中获取文本“购物车中有4个产品”。

    <h2>
     <!-- Plural Case [both cases are needed because page may be updated in Javascript] -->
     <span class="ajax_cart_product_txt_s unvisible" style="display: inline;">
        There are 
        <span class="ajax_cart_quantity">4</span>
        items in your cart.
     </span>
     <!-- Singular Case [both cases are needed because page may be updated in Javascript] -->
     <span class="ajax_cart_product_txt " style="display: none;"> There is 1 item in your cart. </span>
     </h2>

我尝试过使用getText()和innerHTML,但它没有用。

1 个答案:

答案 0 :(得分:0)

如果有帮助,你可以尝试下面的内容:

String text = "return $('.ajax_cart_product_txt_s.unvisible').text();";