NoSuchElementException on performing Mousehover action in selenium - selenium

I have a webpage in which I am trying to perform a mouse hover.. There is an element named "Entity Records" on which if you hover your mouse it displays a menu. In that menu I need to click on an element named Create New record.
I have tried 3 different set of codes but it's not working for me..
1st One:
WebElement el = driver.findElement(By.xpath("\\...."));
action.moveToElement(el).build().perform();
Actions builder = new Actions(driver);
builder.moveToElement(driver.findElement(By.cssSelector("..."))).click().build().perform();
2nd one:
WebElement entityrecordsmenu = driver.findElement(By.cssSelector("..."));
Actions builder = new Actions(driver);
builder.moveToElement(entityrecordsmenu).build().perform();
WebElement createnewrecord = driver.findElement(By.cssSelector("..."));
createnewrecord.click();
3rd one:
Actions action2 = new Actions(driver);
WebElement ele = driver.findElement(By.xpath("...));
action2.moveToElement(ele).build().perform();
Actions build2 = new Actions(driver);
build2.moveToElement(driver.findElement(By.xpath("..."))).click().build().perform();
1st and 2nd code are doing the mouse hover fine, but its not clicking on the menu element. Can anyone suggest me the correct way of doing this?

After mouse hover, try by giving some wait to get that element displayed and then click.
WebElement entityrecordsmenu = driver.findElement(By.cssSelector("..."));
Actions builder = new Actions(driver);
builder.moveToElement(entityrecordsmenu).build().perform();
//provide wait here to display dropdown
driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS);
//some time implicity wait may fails then use thread.sleep
//Thread.sleep(3000);
WebElement createnewrecord = driver.findElement(By.cssSelector("..."));
createnewrecord.click();
//if still above once does not work you can try
Actions builder1 = new Actions(driver);
builder1.moveToElement(entityrecordsmenu).click(driver.findElement(By.cssSelector("..."))).build().perform();
Thank You,
Murali

Related

Access submenu in Selenium using c#

Hi I am trying to access a submenu in selenium using c#. On my the website that I am testing the mouseover to the menu opens another submenu1,mouseover to submenu1 options open submenu2. I want to click on one of the submenu2 options. I tried to run below, everytime it throws an error of element not visible on custonboarding.Click();
Actions builder = new Actions(driver);
driver.Manage().Timeouts().ImplicitlyWait(TimeSpan.FromSeconds(5));
var hoverover = driver.FindElement(By.XPath("menu1"));
builder.MoveToElement(hoverover).Build().Perform();
var hoverover1 = driver.FindElement(By.XPath("submenu1));
builder.MoveToElement(hoverover1).Build().Perform();
var custonboarding = driver.FindElement(By.XPath("submenu2"));
custonboarding.Click();
Can someone help me out here?
It might take some time for the element to fully load. You can use explicit wait and ExpectedConditions to wait for the element to be visible
WebDriverWait wait = new WebDriverWait(driver, TimeSpan.FromSeconds(5));
IWebElement custonboarding = wait.Until(ExpectedConditions.ElementIsVisible(By.XPath("submenu2")));
custonboarding.Click();
This will wait up to 5 seconds for the element to be visible.

How to select the submenu of the flyout using selenium webdriver

I want to select the submenu of the flyout using selenium webdriver.
Also how can I simulate on hover on menu items using selenium.
Please guide or provide some tutorial for the same.
Thanks
Check the actions class, something like this you need:
WebElement element = driver.findElement(By.Id("id"));
Actions builder = new Actions(driver);
Actions hover = builder.moveToElement(element);
hover.build().perform();
String New_select_Just_Landed = "//*[#id='nav1']/a";
WebElement Ba = driver.findElement(By.xpath(New_select_Just_Landed));
WebElement subBa = driver.findElement(By.xpath("//*[#id='nav1']/section/ul/li/a"));
Actions action = new Actions(driver);
action.moveToElement(Ba).perform();
Thread.sleep(2000); System.out.println("Mouse hoover succeed");
action.moveToElement(subBa).perform();
subBa.click();
System.out.println("Click Just Landed! succeed");
Thread.sleep(5000L);

Unable to click a value from a sub list of the main list using mouse over action of selenium webdriver

I am trying to automate a scenario where I can select a value from a sub-menu present under main menu.
Below is the application url:
http://www.jetairways.com/EN/IN/Home.aspx
Its a mouser over functionality and tried to automate the Tab (Plan your travel-> Flights -> Book Online) with the below code but not working:
WebElement we = driver.findElement(By.xpath(".//*[#id='PlanYourTravel']/span/b"));
WebElement we1 = driver.findElement(By.xpath(".//*[#id='lnkThirdLevel58']"));
WebElement we2 = driver.findElement(By.xpath(".//*[#id='ddsubSubmenu58']/li[1]/a"));
Actions builder = new Actions(driver);
WebDriverWait wait = new WebDriverWait(driver, 15, 100);
builder.moveToElement(we).perform();
Thread.sleep(10000);
wait.until(ExpectedConditions.visibilityOf(we1));
builder.moveToElement(we1).perform();
wait.until(ExpectedConditions.visibilityOf(we2));
builder.moveToElement(we2).click().perform();
I am getting the element not visible issue. Quick help on this would be much appreciated.
I have tried with below code to click on "Book Online" and its working fine
WebDriver driver = new FirefoxDriver();
driver.manage().timeouts().implicitlyWait(40, TimeUnit.SECONDS);
driver.get("http://www.jetairways.com/EN/IN/Home.aspx");
Actions actObj = new Actions(driver);
//actObj.moveToElement(driver.findElement(By.xpath("//*[text()='Plan Your Travel']"))
actObj.moveToElement(driver.findElement(By.xpath("//*[#id='PlanYourTravel']/span/b"))).perform();
actObj.moveToElement(driver.findElement(By.xpath("//li[#title='Flights']/a"))).perform();
driver.findElement(By.xpath("//a[#title='Book Online']")).click();

How to do mouseover using webdriver actions?

I'm trying to get element that appear after a mouseover action. how to do ?
I tried:
Actions action = new Actions(driver);
action.moveToElement(elem);
action.perform();
WebElement myDynamicElement = (new WebDriverWait(driver,10)).until(ExpectedConditions.presenceOfElementLocated(By.cssSelector("class*='hoverEverywhereTooltip'")));
this element appear just after the mouse over event.
Try this.
code:
Actions actions = new Actions(driver);
WebElement menuhover = driver.findElement(By.linkText("Menu"));
actions.moveToElement(menuhover);
WebElement subLink = driver.findElement(By.id("submenu"));
actions.moveToElement(submenu);
actions.click();
actions.perform();
it worked I missed [] in my cssSelector properties:
WebElement myDynamicElement = (new WebDriverWait(driver,10)).until(ExpectedConditions.presenceOfElementLocated(By.c‌​ssSelector("[class*='hoverEverywhereTooltip']")));

How to select an element from a menu using Webdriver Selenium ? The Menu drop down shows up on Mouse Over?

How to select an element from a menu using Webdriver Selenium ? The Menu drop down shows up on Mouse Over?
You can check it in two ways:
1) first way is to use actions builder
WebElement mnuElement;
WebElement submnuElement;
mnEle = driver.findElement(By.Id("mnEle")).Click();
sbEle = driver.findElement(By.Id("sbEle")).Click();
Actions builder = new Actions(driver);
// Move cursor to the Main Menu Element
builder.MoveToElement(mnEle).Perform();
// Giving 5 Secs for submenu to be displayed
Thread.sleep(5000L);
// Clicking on the Hidden SubMenu
driver.findElement(By.Id("sbEle")).Click();
See here
2) another approach is to click directly needed element using jscript without simulating mouse hover event:
String cssLocatorOfTheElement=....//locator of the element to click on
JavascriptExecutor js = (JavascriptExecutor) driver;
StringBuilder stringBuilder = new StringBuilder();
stringBuilder.append("var x = $(\'"+cssLocatorOfTheElement+"\');");
stringBuilder.append("x.click();");
js.executeScript(stringBuilder.toString());
hope this works for you)
Simulate mouseOver event and then select element you can like that:
var elementToShowMenu = Driver.FindElement(Byl.Id("some id"));
new Actions(Driver).MoveToElement(elementToShowMenu).Release(elementToShowMenu).Build().Perform();
var menuElement = Driver.FindElement(Byl.Id("your menu id"));
Here is how I click a invisible anchor link on a tag: a link that is generated dynamically by Javascript:
public static void mouseClickByLocator( String cssLocator ) {
String locator = cssLocator;
WebElement el = driver.findElement( By.cssSelector( locator ) );
Actions builder = new Actions(driver);
builder.moveToElement( el ).click( el );
builder.perform();
}
WebElement mnuElement;
WebElement submnuElement;
mnuElement = driver.findElement(By.cssSelector("insert selector here"));
submnuElement = driver.findElement(By.cssSelector("insert selector here"));
Actions builder = new Actions(driver);
// Move cursor to the Main Menu Element
builder.moveToElement(mnuElement).perform();
// Pause 2 Seconds for submenu to be displayed
TimeUnit.SECONDS.sleep(2); //Pause 2 seconds
// Clicking on the Hidden submnuElement
submnuElement.click();