我想所有的菜單頁面的鏈接,以便從每個菜單頁面獲取產品, 這裏是菜單提取菜單鏈接
<nav id="cavas_menu" class="navbar navbar-default" role="navigation">
<!-- Brand and toggle get grouped for better mobile display -->
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div id="leo-top-menu" class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav megamenu"><li class=" parent dropdown aligned-left ">
<a href="#" class="dropdown-toggle has-category" data-toggle="dropdown" target="_self"><span class="menu-title">Categories</span><b class="caret"></b></a><div class="dropdown-sub dropdown-menu" style="width:400px"><div class="dropdown-menu-inner"><div class="row"><div class="mega-col col-sm-6"> <div class="mega-col-inner "><div class="leo-widget"><div class="widget-subcategories">
<div class="widget-inner">
<div class="menu-title">Home</div>
<ul>
<li class="clearfix">
<a href="https://www.vapors.com/14-e-juices" title="E-Juices" class="img">
E-Juices
</a>
</li>
<li class="clearfix">
<a href="https://www.vapors.com/15-mods" title="Mods" class="img">
Mods
</a>
</li>
<li class="clearfix">
<a href="https://www.vapors.com/17-accessories" title="Accessories" class="img">
Accessories
</a>
</li>
<li class="clearfix">
<a href="https://www.vapors.com/19-starter-kits" title="Starter Kits" class="img">
Starter Kits
</a>
</li>
<li class="clearfix">
<a href="https://www.vapors.com/21-ego" title="Ego" class="img">
Ego
</a>
</li>
<li class="clearfix">
<a href="https://www.vapors.com/27-rda" title="RDA" class="img">
RDA
</a>
</li>
<li class="clearfix">
<a href="https://www.vapors.com/28-regulated-mods" title="Regulated Mods" class="img">
Regulated Mods
</a>
</li>
<li class="clearfix">
<a href="https://www.vapors.com/29-clearomizer" title="Clearomizer" class="img">
Clearomizer
</a>
</li>
<li class="clearfix">
<a href="https://www.vapors.com/30-drip-tips" title="Drip Tips" class="img">
Drip Tips
</a>
</li>
<li class="clearfix">
<a href="https://www.vapors.com/33-sales" title="Sales" class="img">
Sales
</a>
</li>
</ul>
</div>
</div>
</div></div></div><div class="mega-col col-sm-6"> <div class="mega-col-inner "><div class="leo-widget"> <div class="widget-products">
<div class="menu-title">
New Products
</div>
<div class="widget-inner">
<div class="product-block">
<div class="product-container clearfix">
<div class="image ">
<a class="product_img_link" href="https://www.vapors.com/rda/794-plume-veil-v25-limited-ed.html" title="Plume Veil V2.5 Limited Ed." itemprop="url">
<img class="replace-2x img-responsive" src="https://www.vapors.com/307-home_default/plume-veil-v25-limited-ed.jpg" alt="Plume Veil V2.5 Limited Ed." title="Plume Veil V2.5 Limited Ed." itemprop="image">
</a>
<span class="new-box">
<span class="new-label">New</span>
</span>
</div>
<div class="product-meta">
<h5 itemprop="name">
<a class="product-name" href="https://www.vapors.com/rda/794-plume-veil-v25-limited-ed.html" title="Plume Veil V2.5 Limited Ed." itemprop="url">
Plume Veil V2.5 Limited Ed.
</a>
</h5>
<p class="product-desc" itemprop="description">
</p>
<div itemprop="offers" itemscope="" itemtype="http://schema.org/Offer" class="content_price">
<span itemprop="price" class="price product-price">
$89.99 </span>
<meta itemprop="priceCurrency" content="1">
</div>
</div>
</div>
<div class="product-container clearfix">
<div class="image ">
<a class="product_img_link" href="https://www.vapors.com/rda/793-plume-veil-v25.html" title="Plume Veil V2.5" itemprop="url">
<img class="replace-2x img-responsive" src="https://www.vapors.com/306-home_default/plume-veil-v25.jpg" alt="Plume Veil V2.5" title="Plume Veil V2.5" itemprop="image">
</a>
<span class="new-box">
<span class="new-label">New</span>
</span>
</div>
<div class="product-meta">
<h5 itemprop="name">
<a class="product-name" href="https://www.vapors.com/rda/793-plume-veil-v25.html" title="Plume Veil V2.5" itemprop="url">
Plume Veil V2.5
</a>
</h5>
<p class="product-desc" itemprop="description">
This all new version of the Veil is a Sub-Ohm V2.5 RDA by...
</p>
<div itemprop="offers" itemscope="" itemtype="http://schema.org/Offer" class="content_price">
<span itemprop="price" class="price product-price">
$89.99 </span>
<meta itemprop="priceCurrency" content="1">
</div>
</div>
</div>
</div>
</div>
</div>
</div></div></div></div></div></div></li><li class="active">
<a href="https://www.vapors.com/14-e-juices" target="_self" class="has-category"><span class="menu-title">E-Juices</span></a></li><li class="">
<a href="https://www.vapors.com/15-mods" target="_self" class="has-category"><span class="menu-title">Mods</span></a></li><li class="">
<a href="https://www.vapors.com/28-regulated-mods" target="_self" class="has-category"><span class="menu-title">Regulated Mods</span></a></li><li class="">
<a href="https://www.vapors.com/27-rda" target="_self" class="has-category"><span class="menu-title">RDA</span></a></li><li class="">
<a href="https://www.vapors.com/19-starter-kits" target="_self" class="has-category"><span class="menu-title">Starter Kits</span></a></li><li class="">
<a href="https://www.vapors.com/29-clearomizer" target="_self" class="has-category"><span class="menu-title">Clearomizer</span></a></li><li class="">
<a href="https://www.vapors.com/30-drip-tips" target="_self" class="has-category"><span class="menu-title">Drip tips</span></a></li><li class="">
<a href="https://www.vapors.com/21-ego" target="_self" class="has-category"><span class="menu-title">Ego</span></a></li><li class="">
<a href="https://www.vapors.com/17-accessories" target="_self" class="has-category"><span class="menu-title">Accessories</span></a></li><li class="sales">
<a href="https://www.vapors.com/33-sales" target="_self" class="has-category"><span class="menu-title">Sales</span></a></li></ul>
</div>
</nav>
HTML代碼,我需要得到所有HREF鏈接,點擊每個鏈接來執行一些操作。
這裏是代碼,我嘗試過,但得到的輸出爲空:
List<WebElement> cat=driver.findElements(By.xpath("//*[@id='cavas_menu']"));
for (WebElement catmenu : cat){
System.out.println(catmenu.getAttribute("href"));
}
}
感謝您的快速回復,但我得到一個錯誤,無效的選擇 –
你需要打開一個新標籤上的鏈接?對不起,已經很快寫好了代碼。現在檢查編輯,我已經測試過了 –
Dude,你試過了嗎? –