0

我想从 iframe 内的日历弹出窗口中单击日期。我在下面写了抛出无法找到元素错误的硒代码。请帮助我编写正确的 xpath 或 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>
4

2 回答 2

0

进入框架后试试这个:

driver.findElement(By.xpath("//div[text()='3']").click();

编辑:

对于 To 选择器:

driver.findElement(By.xpath("//*[@id='NewsSearchDateToInput_selector_monthSelector']//div[text()='3']").click();

对于从选择器:

driver.findElement(By.xpath("//*[@id='NewsSearchDateFromInput_selector_monthSelector']//div[text()='3']").click();
于 2013-04-15T16:36:54.910 回答
0

有帮助吗?//div[@class='daysNumbersStyles'][3]

于 2013-04-15T14:37:04.497 回答