我想点击iframe内的日历弹出窗口中的日期。我写了下面的selenium代码,抛出无法找到元素错误。请帮我写出正确的xpath或selenium代码。我是Selenium的新手
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();
错误:无法找到元素“// 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>
答案 0 :(得分:0)
有帮助吗? // DIV [@类= 'daysNumbersStyles'] [3]
答案 1 :(得分:0)
进入框架后试试这个:
driver.findElement(By.xpath("//div[text()='3']").click();
编辑:
For To选择器:
driver.findElement(By.xpath("//*[@id='NewsSearchDateToInput_selector_monthSelector']//div[text()='3']").click();
对于From选择器:
driver.findElement(By.xpath("//*[@id='NewsSearchDateFromInput_selector_monthSelector']//div[text()='3']").click();