Unable to locate a date picker element when the browser window that selenium is using is minimized

150 views
Skip to first unread message

wamique Ansari

unread,
Feb 25, 2015, 10:05:31 AM2/25/15
to seleniu...@googlegroups.com
Hi Friends,

I am stuck at a point in my test. Description and HTML as below: Please help me. Please let me know if anything else is needed

I am using datepicker to select a new date. The date picker window is launched as a result of clicking the Date Of Birth text box. When the browser window that selenium is using is kept open, the test pass. But when the window is minimized, the test fails with below reason:

org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"xpath","selector":"//select[@class='ui-datepicker-month']"}

HTML: 

<div id="ui-datepicker-div" class="ui-datepicker ui-widget ui-widget-content ui-helper-clearfix ui-corner-all" style="position: absolute; top: 485.617px; left: 208.8px; z-index: 1; display: block;">
      <div class="ui-datepicker-header ui-widget-header ui-helper-clearfix ui-corner-all">
               <a class="ui-datepicker-prev ui-corner-all" title="Prev" data-event="click" data-handler="prev">
               <a class="ui-datepicker-next ui-corner-all" title="Next" data-event="click" data-handler="next">
               <div class="ui-datepicker-title">
                       <select class="ui-datepicker-month" data-event="change" data-handler="selectMonth">
                       <select class="ui-datepicker-year" data-event="change" data-handler="selectYear">
               </div>
       </div>

Code:
       @FindBy(how=How.XPATH , using ="//input[@name='dateOfBirth']")
private WebElement DOB_textbox;
@FindBy(how=How.XPATH , using ="//select[@class='ui-datepicker-month']")
private WebElement DatePickerMonth_dropdown;
@FindBy(how=How.XPATH , using ="//select[@class='ui-datepicker-year']")
private WebElement DatePickerYear_dropdown;


public String SetDOB(String Year,String Month,String Day){
Reporter.log("Prop Mgmt Tenants Page: Select DOB : "+Day+"/"+Month+"/"+Year);
DOB_textbox.click();
WebDriverWait wait1 = new WebDriverWait(driver, 4);
try{
wait1.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//*[@id='ui-datepicker-div']")));
}catch(Exception e){
//e.printStackTrace();
}
WebElement MonthSel= DatePickerMonth_dropdown;
Select sel = new Select(MonthSel);
sel.selectByVisibleText(Month);
WebElement YearSel= DatePickerYear_dropdown;
sel = new Select(YearSel);
sel.selectByVisibleText(Year);

WebElement dateWidget = driver.findElement(By.id("ui-datepicker-div"));
List<WebElement> columns=dateWidget.findElements(By.tagName("td"));
        
for (WebElement cell: columns){
if (cell.getText().equals(Day)){
cell.findElement(By.linkText(Day)).click();
break;
}
        }
return DOB_textbox.getAttribute("value");
}

PeterJeffreyGale

unread,
Feb 25, 2015, 10:09:53 AM2/25/15
to seleniu...@googlegroups.com
A real user cannot interact with a browser that is minimized. I don't think you can expect webdriver to work with minimized windows either.

wamique Ansari

unread,
Feb 26, 2015, 1:51:06 AM2/26/15
to seleniu...@googlegroups.com
Hi Peter,

But everything else works with the browser window minimized except this.

PeterJeffreyGale

unread,
Feb 26, 2015, 3:26:21 AM2/26/15
to seleniu...@googlegroups.com
Jut because SOME things work when minimized, it't doesn't mean that EVERY thing will. 

I don't think WebDriver is guaranteed to run minimized, indeed, IE has to be run maximized.

If you need to use your PC while running your automation, I would suggest that you need a second PC.

wamique Ansari

unread,
Feb 26, 2015, 4:34:14 AM2/26/15
to seleniu...@googlegroups.com
Hi Peter,

Thanks for the reply. Yes true.

Anyways, I found a workaround by directly sending the date as string in the Date of Birth text box which works even after minimizing the browser window. :)

Thanks for all the help. This group rocks :D
Reply all
Reply to author
Forward
0 new messages