How can the cursor be focus on a specific input box on page load?
The button is “Add new appointment” the script is:
<input type="button" onclick="open_win()" value="add new appointment"/>
WebElement ek = driver.findElement(By.xpath("//input[@value='add new appointment']"));
jse.executeScript("arguments[0].click();", ek);
This opens a pop up window. Now I need to focus on the window.
Ajax is used to retrieve information from this pop up.
I tried every aspect to focus on the new pop up. The input txt fields are hidden, The code that I’ve tried is:
jse.executeScript("window.focus();");
driver.switchTo().defaultContent();
driver.switchTo().activeElement().findElement(By.xpath("//*[@id='barge:bargeId:txtInput']"));
driver.switchTo().alert();
I thought to focus on the text field with the following code:
jse.executeScript("document.getElementById('barge:bargeId:txtInput')[0].setAttribute('type', 'text');");
driver.findElement(By.xpath("//*[@id='barge:bargeId:txtInput']")).sendKeys("suxs");
This also haven’t worked.
Even jse.executeScript("document.title") has not worked.
the code for text field
<span id="barge:bargeId:input">
<input id="barge:bargeId:txtInput" class="ui-inputfield ui-inputtext ui-widget ui-state-default ui-corner-all inputbox doubleInputbox ui-state-hover" type="text" tabindex="" maxlength="17" accesskey="" name="barge:bargeId:txtInput" role="textbox" aria-disabled="false" aria-readonly="false" aria-multiline="false"/>
</span>
to click on the button you can simple do this:
driver.findElement(By.xpath("//input[@value='add new appointment']")).click();By saying “This opens a pop up window” do you mean an actual new window, new tab or dialog like this or like this?
I think it opens up the
dialog, and in this case usually it’s just another element on the page. And in this case this should work:UPDATE:
Since it’s a new window, there ways to switch to the new window described here:
Also, it would be helpful to check the code of
open_win()javascript function.