Hover over the element
As soon as we hover there will be
- A text box
- A Submit button to click
Firstly, I have to hover
with mouse and then enter the values in the Textbox
and then click on Submit
button.
Hover over the element
As soon as we hover there will be
Firstly, I have to hover
with mouse and then enter the values in the Textbox
and then click on Submit
button.
Please refer to the below code to perform the required operation.
// Initializing the action class
Actions action = new Actions(driver);
// Moving to the element
action.moveToElement(<WebElement>).build().perform();
// Entering the text in the text box
action.moveToElement(<WebElement of Textbox>).sendKeys("Text").build().perform();
// Clicking on the submit button
action.moveToElement(<WebElement of submit button>).click().build().perform();
or you can combine all the above actions into single action.
Actions action = new Actions(driver);
action.moveToElement(<Element which displayes text box>).moveToElement(<Element of textbox>).sendKeys("Text").moveToElement(<Element of submit button>).click().build().perform();
Hope this helps.
(Amusing you are using java) According to your approach, you should try using Mouse
to perform mouse over on the element then find element using WebDriverWait
to wait until element visible as below :-
import org.openqa.selenium.interactions.HasInputDevices
import org.openqa.selenium.interactions.Mouse
import org.openqa.selenium.internal.Locatable;
WebDriverWait wait = new WebDriverWait(driver, 10);
//Find element first where you want to hover
WebElement hoverElement = wait.until(ExpectedConditions.visibilityOfElementLocated(byObject));
Mouse mouse = ((HasInputDevices)driver).getMouse();
mouse.mouseMove(((Locatable)hoverElement).getCoordinates()); //it will perform mouse over on desire element
//Now after mouse over you can find the desire text box
WebElement textBox = wait.until(ExpectedConditions.visibilityOfElementLocated(byObject));
users.sendKeys("your value"); //It will set the value on text box
//Now you can find the desire submit button
WebElement submit = wait.until(ExpectedConditions.elementToBeClickable(byObject));
submit.click(); //It will click on submit button
Edited :- If unfortunately mouse over does not work using Mouse
, you can use JavascriptExecutor
to perform mouse over as below :-
JavascriptExecutor js = (JavascriptExecutor)driver;
executor.executeScript("function triggerMouseEvent (node, eventType) {"
+ "var clickEvent = document.createEvent ('MouseEvents');"
+ "clickEvent.initEvent (eventType, true, true);"
+ "node.dispatchEvent (clickEvent);"
+ "}triggerMouseEvent (arguments[0], 'mouseover');", hoverElement);
Hope it helps..:)