我想單擊日曆彈出窗口中的內部iframe中的日期。我寫下了硒代碼,拋出無法找到元素錯誤。請幫我寫出正確的xpath或selenium代碼。我是新來硒無法點擊日曆彈出的日期
硒代碼:
WebElement iframe =driver.findElement(By.id("NewsSearchDateToInput_selector_iframe"));
driver.switchTo().frame(iframe);
//clicking on date 3
driver.findElement(By.xpath("//div[3][@class='daysNumbersStyles']")).click();
Error: unable to locate the element "//div[3][@class='daysNumbersStyles']"
HTML標籤:
<iframe id="NewsSearchDateToInput_selector_iframe"
class="dateTimeSelectorContainerStyle altFlexibleContainer"
src="javascript:false;"
style="left: 1216px; top: 245px; width: 249px; height: 207px;
display: block;"/>
<div class="dateTimeSelectorContainerStyle altFlexibleContainer"
style="top: 245px; left: 1216px; display: block;">
<div class="top">
<div class="content">
<div class="dateSelectorHeader">
<div class="dateSelectorBody">
<div class="yearMonthSelectorStyle">
<div id="NewsSearchDateToInput_selector_monthSelector" class="monthSelectorListStyle">
<div class="daysStyle">
<div>
<div class="daysNumbersDivStyle">
<div class="daysNumbersStyles">1</div>
<div class="daysNumbersStyles">2</div>
<div class="daysNumbersStyles">3</div>
它找到兩個元素,1 f或FromDate日曆和第二個ToDate日曆。 – user2282679
你可以修改一下// div [@ id ='FromDate'] // div [@ class ='daysNumbersStyles'] [3]類似的東西 – buddy
看起來像它沒有切換到框架本身。 iframe能夠在xpath表達式中找到,但不能在webdriver中找到。任何其他方式,我們可以切換到框架? – user2282679