2016-12-01 117 views
0

我想使用Java在Selenium Webdriver中获取文本“您的购物车中有4种产品”。在Selenium Webdriver中提取隐藏的元素文本

<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

采用javascript ...硒只对可见元素交互... – Grasshopper

+0

这可能是一个例子http://stackoverflow.com/questions/13047056/如何阅读的文本 - 从隐藏的元素与 - 硒的webdriver – Rockme

回答

0

你可以试试下面是否有帮助:

String text = "return $('.ajax_cart_product_txt_s.unvisible').text();"; 
相关问题