2016-06-13 78 views
-1

任何人都可以提供幫助,我試圖獲取表示智能卡按鈕的最後一個xpath元素(例如633597015500042010),然後點擊它。我試過以下方法,但仍找不到解決方案。我打算捕捉的按鈕的名稱是「選擇」。 ();}}。點擊();}}。點擊鼠標右鍵,彈出一個對話框。按鈕的最後一個元素

<html class="js flexbox flexboxlegacy canvas canvastext postmessage no-websqldatabase indexeddb hashchange history draganddrop websockets rgba hsla multiplebgs backgroundsize borderimage borderradius boxshadow textshadow opacity cssanimations csscolumns cssgradients no-cssreflections csstransforms csstransforms3d csstransitions fontface generatedcontent video audio localstorage sessionstorage webworkers applicationcache desktop" lang="en"> 
<head> 
<body class="rwd"> 
<noscript> <iframe src="//www.googletagmanager.com/ns.html?id=GTM-KZFHXV" height="0" width="0" style="display:none;visibility:hidden"></iframe> </noscript> 
<script> 
<div class="page-wrapper page-wrapper-delivery"> 
<div> 
<div class="wrapper-wide wrapper-header" style="position: relative;"> 
<div class="wrapper-wide wrapper-body"> 
<div class="wrapper"> 
<div class="main"> 
<a id="skipnav" tabindex="-1"></a> 
<div class="row hidden"> 
<div class="row"> 
<div class="row"> 
<div class="cf"></div> 
<div class="row"> 
<div class="pane base12"> 
<form class="cf javascript-validate" novalidate="novalidate"> 
<div class="component checkout-page cf"> 
<div class="component ticket-item-base ticket-item-checkout cf"> 
<div class="cf"> 
<div class="component smart-card-checkout cf"> 
<div class="component vertical-accordion stag-standard-accordion checkout-accordion parent-accordion cf"> 
<ul id="accordion-1" class="accordion single-display"> 
<li class="cf open-li"> 
<a class="toggle-link open" href="#"> Select/request a smart card </a> 
<a class="edit-link secondary-toggle-link" href="#">Edit</a> 
<div class="accordion-drop" style="display: block;"> 
<div class="accordion-content cf"> 
<div class="component vertical-accordion stag-standard-accordion child-accordion cf"> 
<ul id="accordion-2" class="accordion multi-display"> 
<li class="cf open-li"> 
<a class="toggle-link open" href="#">Select a smart card</a> 
<div class="accordion-drop" style="display: block;"> 
<div class="accordion-content cf"> 
<div class="info-box"> 
<form class="select-card-form" novalidate="" method="post"> 
<input type="hidden" value="SmartCardSelect_6822d668-9a46-4b51-910d-98c701d43fa2" name="FormName"> 
<input type="hidden" value="e3429d28-e838-4247-9a4e-0b3dc53cf1a7" name="CardId"> 
<div class="select-item "> 
<p>Smart card 1</p> 
<button class="submit-btn uniform-button button-smaller button-orange select-address" data-id="633597015500041558"> 
</div> 
</form> 
<form class="select-card-form" novalidate="" method="post"> 
<form class="select-card-form" novalidate="" method="post"> 
<form class="select-card-form" novalidate="" method="post"> 
<form class="select-card-form" novalidate="" method="post"> 
<form class="select-card-form" novalidate="" method="post"> 
<form class="select-card-form" novalidate="" method="post"> 
<input type="hidden" value="SmartCardSelect_6822d668-9a46-4b51-910d-98c701d43fa2" name="FormName"> 
<input type="hidden" value="94888c8a-815c-484e-808c-8d400694b9e9" name="CardId"> 
<div class="select-item "> 
<p>Smart card 7</p> 
<button class="submit-btn uniform-button button-smaller button-orange select-address" data-id="633597015500042010"> 
<span>Select</span> 
</button> 
</div> 
</form> 
<form class="select-card-form" novalidate="" method="post"> 
<form class="select-card-form" novalidate="" method="post"> 
<form class="select-card-form" novalidate="" method="post"> 
</div> 
</div> 
</li> 
<li class="cf"> 
<li class="cf"> 
</ul> 
</div> 
</div> 
</div> 
</li> 
</ul> 
</div> 
</div> 
<div class="component checkout-date-select cf no-end-date"> 
</div> 
</div> 
</div> 
</div> 
<div class="row"> 
<div class="row"> 
</div> 
</div> 
</div>`enter code here` 
+0

任何人的位置?..- :) – AzMar

+1

一個HTML的縮進會有所幫助。該html似乎不完整,也不必發佈所有的HTML,只有主要部分與你需要的元素。試着爲你的元素標識一個獨特的父母,也可以試試這個:// span [text ()='Select']/parent :: button – lauda

回答

0

根據提供的HTML代碼,所需的元素在框架內,所以我們需要切換到該框架。切換到幀後,查找該按鈕

在代碼中,使用的xpath不正確。它應該是這樣的

(//div[@class='select-item']/button)[last()] 

考慮,您正試圖找到解決以下元素

<button class="submit-btn uniform-button button-smaller button-orange select-address" data-id="633597015500042010"> 
+0

我試圖切換到如下框架,但仍然無法讓它工作 - 任何想法爲什麼? :driver.switchTo()。frame(「submit-btn uniform-b​​utton button-smaller button-orange select-address」); driver.findElement(By.xpath( 「// DIV [@類= '選擇項'] /按鈕)[最後]」))點擊(); – AzMar

+0

不......這是錯的。框架的意思是HTML格式,它以