2016-04-04 8 views
-3

1.HTMLiは1以上H2、それぞれに& H3タグをしたwebdriverを

<div id="page-filter1"> 
**<h3>** 
    Browse Category 
**</h3>** 
<ul class="mt-accordion multiple"> 
    <li id="phdesktopbody_0_phdesktopfilterbycategory_0_liAllProduct" class="cls-8dcbcbac-2fef-4231-9641-d61818abe0e0 item-1 odd first odd"> 
     <a id="phdesktopbody_0_phdesktopfilterbycategory_0_hypAllProducts" href="/en-us/products">All Products</a> 
    </li> 
<div class="span12"> 
    <h3 class="onelayout-heading"> 
     <strong><em>Callout <sub>&copy;</sub>itle<sup>x</sup></em></strong> 
    </h3> 
</div> 
<div id="phdesktopbody_0_phdesktopflexiblepromo_0_phdesktoppromocontentarea6b299d9421684ceaaed7c23ebee57f57_0_panelSubheadlineandCTASection" class="span7 pull-left"> 

セレンを使用して、HTMLからH1、H2、H3タグの値を抽出する方法ページ、 クラス名と説明が毎回変わります。plはタグを特定し、そこから値を抽出するのに役立ちます。

答えて

0

こんにちはArjun Vcは、クラス名と説明が毎回変わっても同じようにしてください。

driver.get("http://www.seleniumhq.com"); // link to your web page 

     // working with H1 H2 .... tags 

     String TagToWorkWith = "h1"; // here simply change the tag name on which you want to work 
     List<WebElement> myTags = driver.findElements(By.tagName(TagToWorkWith)); 

     // now extracting the vale 
     // this for loop will print/extract all the values for tag 'H1'. 
     for(int i=0;i<myTags.size();i++){ 
      // extracting tags text 
      System.out.println(TagToWorkWith + " value is : " + myTags.get(i).getText()); 
     } 
+0

Rajnishさん、ありがとう、これは私が必要としていたものです。 –

+0

あなたの歓迎はそれをあなたの答えとしてマークしました –

関連する問題