我試圖使用硒的webdriver在Gmail註冊的Web應用程序中提取文本從出生月份字段(一個月的名稱,如一月,二月...)文本。代碼如下所示:獲得使用硒嵌套div標籤的webdriver
<label id="month-label" class="month">
<span id="BirthMonth" class=" form-error" aria-invalid="true">
<div class="goog-inline-block goog-flat-menu-button jfk-select" role="listbox" style="-moz-user-select: none;" aria-expanded="false" tabindex="0" aria-haspopup="true" aria-activedescendant=":0" title="Birthday">
<div class="goog-menu goog-menu-vertical" style="-moz-user-select: none; visibility: visible; left: 0px; top: -299.133px; display: none;" role="listbox" aria-haspopup="true">
<div id=":1" class="goog-menuitem" role="option" style="-moz-user-select: none;">
<div class="goog-menuitem-content">January</div>
</div>
<div id=":2" class="goog-menuitem" role="option" style="-moz-user-select: none;">
<div class="goog-menuitem-content">February</div>
</div>
<div id=":3" class="goog-menuitem" role="option" style="-moz-user-select: none;">
<div class="goog-menuitem-content">March</div>
</div>
<div id=":4" class="goog-menuitem" role="option" style="-moz-user-select: none;">
<div class="goog-menuitem-content">April</div>
</div>
<div id=":5" class="goog-menuitem" role="option" style="-moz-user-select: none;">
<div id=":6" class="goog-menuitem" role="option" style="-moz-user-select: none;">
<div id=":7" class="goog-menuitem" role="option" style="-moz-user-select: none;">
<div id=":8" class="goog-menuitem" role="option" style="-moz-user-select: none;">
<div id=":9" class="goog-menuitem" role="option" style="-moz-user-select: none;">
<div id=":a" class="goog-menuitem" role="option" style="-moz-user-select: none;">
<div id=":b" class="goog-menuitem" role="option" style="-moz-user-select: none;">
<div id=":c" class="goog-menuitem" role="option" style="-moz-user-select: none;">
</div>
<input id="HiddenBirthMonth" name="BirthMonth" type="hidden">
</span>
</label>
我嘗試起訴xpath和其他元素定位器,但無法提取文本。當我使用Select類時,出現錯誤cannot apply select with div
。請提出一些解決方案。
分享你的代碼你試過的東西 – thebadguy
嘗試了以下代碼:Select months = new Select(driver.findbyelement(By.xpath(「// div [@class =''goog-menu goog-menu-vertical] /格「))); 列表 months_options = months.getOptions(); (i)0; i
不能使用'選擇()'和'div'元素,用簡單的'點擊()',而不是 – Andersson