Robot Framework not clicking dropdown menu in firefox - selenium

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?

Related

Selenium finds the element (anchor) but still says element not visible?

I have a "clear all" button which is an anchor. The HTML structure is like this:
<div class="form-row toggle-closed" id="ProductFilters" style="display: block;">
<div class="form-row__filter">
<ul class="form-row__filter__bg-display">
<li class="filter__group__item__small">
<a id="ProductFiltersFilterText" class="f-right" data-select-all="ProductFilters" href="#">clear all</a>
</li>
</ul>
</div>
</div>
Then in the Selenium test I'm trying to find the a tag using this:
SeleniumHelper.ExpandFilterSection(_webDriver, "#ProductFilters");
var clearAllButton = _webDriver.FindElement(By.CssSelector("div.form-row__filter>ul>li>#ProductFiltersFilterText"));
clearAllButton.Click();
THen I started debugging, in the automated Chrome window I could see that by executing ExpandFilterSection, the filter was expanded, the "clear all" button was exposed, then a bug said:
OpenQA.Selenium.ElementNotVisibleException: 'element not visible'
How ever in the Autos I see:
It seems that the "clear all" button is found, why does it say "element not visible"? Functionality of the button is trigger by JavaScript though.
To click() on the element with text as clear all you have to induce WebDriverWait for the desired ElementToBeClickable() and you can use either of the following Locator Strategies:
linkText:
SeleniumHelper.ExpandFilterSection(_webDriver, "#ProductFilters");
new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.LinkText("clear all"))).Click();
cssSelector:
SeleniumHelper.ExpandFilterSection(_webDriver, "#ProductFilters");
new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.CssSelector("div#ProductFilters>div.form-row__filter>ul.form-row__filter__bg-display>li.filter__group__item__small>a#ProductFiltersFilterText"))).Click();
xpath:
SeleniumHelper.ExpandFilterSection(_webDriver, "#ProductFilters");
new WebDriverWait(driver, TimeSpan.FromSeconds(20)).Until(ExpectedConditions.ElementToBeClickable(By.XPath("//div[#id='ProductFilters']/div[#class='form-row__filter']/ul[#class='form-row__filter__bg-display']/li[#class='filter__group__item__small']/a[#id='ProductFiltersFilterText']"))).Click();

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')]"

Puppeteer (1.14.0) unable to find anchor tag by "id" although JQuery can find it

Node v10.15.3 (64-bit)
Puppeteer v1.14.0
Chromium v 75.0.3738.0 (Developer Build) (64-bit)
I am at the very last page of a site automation tool and the last button I need to press (which is actually an anchor tag with an "id" attribute) cannot be found by Puppeteer. The code is:
await page2.click('#____bs');
The error I receive is:
Error: Node is either not visible or not an HTMLElement
The HTML code is here:
<a role="button" ct="Button" rel="tooltip" title="Post"
aria-label="Please Select Post" data-toggle="cso-button" id="____bq"
class="cso-btn cso-btn cso-action cso-corner cso-btn-primary "
href="javascript:void(0)"
data-ctl-options="{'actiontype';:'ACTION','value':'Click'}"
style="display: inline-block;">Post</a>
While in debug mode with this page up, I can use JQuery to find the element easily:
$("#____bq").text()
"Post"
Therefore, why can't Puppeteer find it? Is there an alternate way I could try to click this link?
Could it also be that the control (the anchor) is outside the visible edge of the screen? I wouldn't think that would matter since I'm assuming Puppeteer is looking at the HTML and not the screen itself but doesn't hurt to ask.
Thanks in advance.
UPDATE: Here's the entire HTML that contains the anchor I'm trying to select:
<div class="row split">
<div class="clsFP-expand clsBG-expand cso-hidden cso-cont-50r cso-pad5r">
<span class="cso-pad5-ie">
<a role="button" ct="Button" rel="tooltip" title="Cancel" aria-label="Please Select Cancel" data-toggle="cso-button" id="____bo" class="cso-btn cso-btn cso-action cso-corner cso-btn-grey " href="javascript:void(0)" data-ctl-options="{"actiontype":"ACTION","value":"Click"}" >Cancel</a>
</span>
<span class="cso-pad5-ie">
<a role="button" ct="Button" rel="tooltip" title="Post" aria-label="Please Select Post" data-toggle="cso-button" id="____bs" class="cso-btn cso-btn cso-action cso-corner cso-btn-primary inactive " href="javascript:void(0)" data-ctl-options="" >Post</a>
<a role="button" ct="Button" rel="tooltip" title="Post" aria-label="Please Select Post" data-toggle="cso-button" id="____bq" class="cso-btn cso-btn cso-action cso-corner cso-btn-primary " href="javascript:void(0)" data-ctl-options="{"actiontype":"ACTION","value":"Click"}" >Post</a>
</span>
</div>
</div>
It's not that Puppeteer is not being able to get the element. That's a validation coming from Puppeteer (see https://github.com/GoogleChrome/puppeteer/blob/5ee21d97e796263857b9f3fbeaf63366179d346f/lib/JSHandle.js#L203).
According to the doc:
This method fetches an element with selector, scrolls it into view if needed, and then uses page.mouse to click in the center of the element. If there's no element matching selector, the method throws an error.
That means that Chromium should be able to scroll to that element, and that element should be visible in order to be able to click on it.

Unable to select<Div> dropdown in Selenium webdriver

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()

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.