Unable to select<Div> dropdown in Selenium webdriver - selenium

enter image description here
HTML For the page
<a id="navigation.batch" Class="more" href="../../../ratingbatch/summary">
<div Class="nested">
<ul class="dropdown-menu">
<li>
<a id="id3" href="../../../ratingbatch/summary">Summary</a>
<a id="id4" href="../../../ratingbatch/search">Search</a>
For the above dropdown menu I am unable to select Menu as well as dropdown links
Tried all most all the options online but nothing seems to be working.
I am getting all the time null pointer exception error.
Can someone help me to resolve this issue. Thanks in advance
My code is as below:
driver.manage().window().maximize();
WebElement mnuElement;
mnuElement = driver.findElement(By.xpath("/html/body/div[1]/div[2]/div[2]/div[1]/div[1]/ul/li[2]/a"));
Actions builder = new Actions(driver);
// Move cursor to the Main Menu Element
builder.moveToElement(mnuElement).perform();
// Giving 5 Secs for submenu to be displayed
Thread.sleep(5000L);
// Clicking on the Hidden SubMenu
driver.findElement(By.id("id4")).click();

It seems your drop-down menu is not open. So I will suggest you to do below things:
Click On drop-down control to open it.
Wait for list item to appear.
Then use code
new Actions(driver).moveToElement(driver.findElement(By.id("id4")),5,5).click().perform()

Related

Robot Framework not clicking dropdown menu in firefox

I've been trying to navigate through a webpage and testing the different links using Robot and Selenium.
I need to click several Dropdown menus. In Google chrome it works fine, but when I use Firefox there will always be one dropdown menu (not always the same one) that will appear selected (Like when a mouse passes over a button), but it will not get clicked.
The code I've been using:
Wait Until Element Is Visible //*[#id="Modules"]/a timeout=20s
Click Element //*[#id="Modules"]/a
Wait Until Element Is Visible xpath: //*[contains(text(), "Tasklist")] timeout=20s
Click Element xpath: //*[contains(text(), "Tasklist")]
This is the element HTML code:
<li id="Modules" class="nav-item nav-item-levels mega-menu-full show">
<a href="#" class="navbar-nav-link dropdown-toggle" data- toggle="dropdown" aria-expanded="true">
<i class="fa fa-lg fa-modx"></i>
<span class="menu-item-name" style="color: inherit; display: none;">Modules</span></a>
And this is the screen I'm trying to click on (In my test case, the "modules" dropdown menu appears selected, but the menu doesn't drop down)
Screenshot
So far I've tried increasing selenium_speed and adding a sleep command before clicking, but nothing seems to work.
Anyone knows what the problem with Firefox could be?

How to click on the center of the button using selenium java? Which position of the button is actually getting clicked when button is identified?

I have button in our website, and border areas of the button is not clickable. So, i need to make sure the button is getting clicked at the center. Is it possible via selenium?
I tried using coorinates, but it is not recommended for our scenario.
xpath used : //div/button[#id='clickme']
<div class="col-lg-10 col-sm-12 p-0 pt-4">
<button class="click mb-3 " tabindex="0" id="clickme">+ Click Here</button>
</div>
Java code used to click
WebElement button = driver.findElement(By.id("clickme"));
button.click();
I guess the click is happening sometimes[2 out of 10 times] on the border where it is not clickable(hand symbol not shown) . As a result report says the click action happened, but there is no event fired on the website.
To identify the element with text as Click Here you can use either of the following Locator Strategies:
cssSelector:
"button.click#clickme"
xpath:
"//button[contains(#class, 'click') and #id='clickme'][contains(., 'Click Here')]"

How do I move hover to the following element and then click on the visible button?

This is the element I want my mouse to move on. <div id="div282" class="divAsset">
On Mouse hover, a few elements would be visible and I want to click on
<a class="tileDownloadButton button" title="Download" target="_blank" href="xxxxx"> Download </a>
How do I move hover to the following element and then click on the visible button?
Python
asset = driver.find_element_by_id("div282")
action.move_to_element(asset).perform();
button = driver.find_element_by_xpath("//a[contains(text(),'Download')]");
button.click()
Java
Actions action = new Actions(driver);
action.moveToElement(driver.findElement(By.id("div282"))).perform();
driver.findElement(By.xpath("//a[contains(text(),'Download')]")).click();
You can execute jquery to hover on element.
Example in python.
driver.execute_script("$('.classname').trigger('mouseover')") #selecting element based on classname.
Example in Java:
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("$('.classname').trigger('mouseover')");
This will make the elements visible and then you can easily click on the elements.
see other jquery selectors here

selenium testing a tooltip for an inactive button

on whom I am able to click, on clicking , nothing happens, i.e. the action is disabled. However, a tooltip gets displayed. The tooltip appears only when we focus on the button.
The html of the button is as follows:
<button type="button" style="color:#ffffff;" rel="rel-517347" data-toggle="popover" data-animation="true" data-placement="top" data-html="true" data-trigger="hover" data-content="<span class='text-center'>
<div>Ride can only be edited before </div><div>1 hour of pickup time.</div>
</span>" class="btn btn-default disbleBtn width_100" data-original-title="" title="">Edit Ride</button>
where Ride can only be edited before is the tooltip.
How can i verify the text of the tooltip as it keeps getting destroyed.
Note that isEnabled() function returns true here as i can click on the button, but no action takes place.
Is there any way I can verify the class of the button i.e btn btn-default disbleBtn width_100 ?
Is there any function or method for it?
I supposed you need to hover not click on the button. When hover tooltip is showing and than you click immediately and tooltip gone.
Do it manually with chrome devtools, open devtools-> sources tab, hover on the button and press F8 to pause then inspect tooltip element. After you get selector for tooltip try codes below:
new Actions(driver).moveToElement(buttonElement).perform();
String tooltipText = new WebDriverWait(driver, 10)
.until(ExpectedConditions.visibilityOfElementLocated(toolTipLocator).getText();
//Verify
Or try this:
new Actions(driver).moveToElement(buttonElement).perform();
new WebDriverWait(driver, 10)
.until(ExpectedConditions.textToBePresentInElementLocated(toolTipLocator, textToVerify)

Selenium: Click on element in div container doesn't work

Fyi: I'm using the selenium package for R, the selection code is equal to javascript or python so I'm asking a general selenium question.
I have a container which I have to make visible by a click, this works.
Then I try to select an element inside this container, I think I find it correctly but the click on the element only makes the popup window disappear.
Example code:
<div class="dateRanges" style="top: 275.313px; display: block;">
<a class="top dateOption CUSTOM" id="id32" href="javascript:;">
Benutzerdefinierter Zeitraum
</a>
<a class="dateOption TODAY" id="id33" href="javascript:;">
Heute
</a>
...
</div>
Element I try to find is "top dateOption CUSTOM".
My different tries which all failed:
remDr$findElement(using = 'xpath','//a[contains(#class,"top")]')$clickElement()
remDr$findElement(value = '//a[#class = "top dateOption CUSTOM"]')$clickElement()
remDr$findElements(using = 'css selector','a[class="top dateOption CUSTOM"]')[[1]]$clickElement()
I don't get any error message, the click seems to happen as the popup disappears, but the effect of the button does not.
I tried to save the object, wait a few seconds and click afterwards with no different effect.
I also tried different approaches with "idc4" with the same outcome.
Would appreciate any help, thank you.