How to click an element that's not visible in Cypress? - automation

I got this error running a test in Cypress:
Timed out retrying after 10050ms: cy.click() failed because this element is not visible:
How can I click on it anyway? It's just a menu item and I don't need it to be visible for my test.

You have to add {force: true} and it should make the click happen:
cy.get('locator').click({force: true})

Related

How to get selenium to scroll to an element (Typescript)?

I'm using jest and selenium. I recently ran into an issue where a sticky footer I have is blocking the element I want to click on. I get the error: 'ElementClickInterceptedError: element click intercepted: Element is not clickable at point (988, 1108)'.
I have tried adding a function =>
this.driver.executeScript("arguments[0].scrollIntoView ;", element);
}
but I get this error: 'JavascriptError: javascript error: arguments[0].scrollIntoView is not a function'.
How do I get selenium to scroll to an element so I can click it using typescript/jest?

Getting ElementClickIntercepted Exception on Firefox browser because a pop up is interfering (chrome works fine)

1.Newsletter pop up shows up on my site.
2.This newsletter pop up modal can show up on any page within 3 minutes so I can not time it.
This was making my automation script (using geb-spock) fail.
In order to now show the newsletter pop up modal, I added a below cookies.
driver.manage().addCookie(new Cookie("signupNoThanks", "optedNoThanks"));
Error message
`selenium.ElementClickInterceptedException` error i.e `Element <element1> is not clickable at point (1085,112) because another element <Newletter pop up modal> obscures it`
I tried to print the cookies and I can see it in the logs
[![Cookies log ss][1]][1]
Can anyone suggest what's wrong on the Firefox browser, cookies added by me works perfectly fine on chrome but fails some automated test cases sometimes on firefox. Is firefox blocking us because of some security reasons?
[1]: https://i.stack.imgur.com/lS1r7.png
The error does seem to be specific to cookies, as you are able to see the cookies in the log. The error 'Element is not clickable' is a generic error you can read more about it on Selenium Web Driver & Java. Element is not clickable at point (x, y). Other element would receive the click
Try the following ways to resolve this error
Try using a different selector like XPath to locate the element.
The element is not visible in the Viewport, could you try scrolling to the element before clicking on it?
Use Actions class to perform the click.
You could create an extension method for clicks used throughout the project and wrap it in a try catch for element intercepted exception. You could then accept the popup and continue on as normal without caring about it.
(below code is c#):
public static class SeleniumExtensions
{
public static void ClickElement(this IWebElement element)
{
try
{
element.Click();
} catch (ElementClickInterceptedException ex)
{
Console.WriteLine("Click was intercepted, attempting to dismiss pop up: ", ex);
//Code to click or dismiss your popup goes here
//retry click
element.Click();
}
}
}
Then throughout the project instead of using the default selenium click use:
element.ClickElement();

selenium.JavascriptException: javascript error: Failed to execute 'elementFromPoint' on 'Document': The provided double value is non-finite

using chrome 78 and chromedriver78
When i click an audio file or try to stop an audio using selenium tests i am getting this error.
Error:
org.openqa.selenium.JavascriptException: javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite.
Note it happens only with remote webdriver and its not consistent.
Error stack trace:
When the audio player of the "item_1" element is stopped in "[data-rcfid='checkbox_7']"
org.openqa.selenium.JavascriptException: javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite.
(Session info: chrome=78.0.3904.70)
Build info: version: '3.11.0', revision: 'e59cfb3', time: '2018-03-11T20:26:55.152Z'
System info: host: 'ip-10-0-10-137', ip: '10.0.10.137', os.name: 'Linux', os.arch: 'amd64', os.version: '4.4.0-71-generic', java.version: '1.8.0_111'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: true, browserName: chrome, browserVersion: 78.0.3904.70, chrome: {chromedriverVersion: 78.0.3904.70 (edb9c9f3de024..., userDataDir: C:\Windows\proxy\scoped_dir...}, goog:chromeOptions: {debuggerAddress: localhost:1674}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: XP, platformName: XP, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: accept, webdriver.remote.sessionid: eb7d4195af3426c181317a16028...}
Session ID: eb7d4195af3426c181317a160286b15e0125b619
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:423)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:187)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:122)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:49)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:158)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:545)
at org.openqa.selenium.remote.RemoteWebDriver.perform(RemoteWebDriver.java:611)
at org.openqa.selenium.interactions.Actions$BuiltAction.perform(Actions.java:638)
at webDriver.Driver.click(Driver.java:147)
at pageObjects.ActivityPageObject.clickAudioInlineStopIn(ActivityPageObject.java:205)
at stepDefinition.Activity.theAudioPlayerOfTheElementIsStoppedIn(Activity.java:61)
at ✽.When the audio player of the "item_1" element is stopped in "[data-rcfid='checkbox_7']"(/opt/atlassian/bamboo-home/xml-data/build-dir/16744451/RCF1-RMIT-BROW3/rcf-automation-tests/src/test/resources/featureFiles/interactions/markedInteractions/CheckBox.feature:433)
I had same issue and observation was , multiple elements by same xpath. Finding different unique xpath resolved it
I have faced the same issue and was able to resolve it by simply scrolling the window down to the element I am targeting. Seems like the element wasn't showing in the viewport and that's why it wasn't visible to selenium.
Try to add the following lines before finding and clicking the element:
driver.execute_script("window.scrollTo(0, window.scrollY + 100)")
driver.implicitly_wait(3)
I experienced this same issue while trying to click a cell in an AngularJS grid. I confirmed that my XPath query resulted in only one result, and then explored if adding in a Wait Condition would help. As it turned out, adding in a Wait here allowed the code to continue without error.
The below code is the method I used to click the cell. I switched from Click() to an Action as the Click() method was being intercepted by a different element.
public void ClickEmploymentChangeLogButton()
{
Wait.Until(WaitConditions.ElementIsVisibleAndEnabled(EmploymentChangeLogButton));
Actions actions = new Actions(driver);
actions.MoveToElement(EmploymentChangeLogButton).Perform();
actions.MoveToElement(EmploymentChangeLogButton).Click().Perform();
}
WaitConditions is a separate class to model some of the behaviour of the deprecated ExpectedConditions package.
Here's the method inside WaitConditions that is used above.
public static Func<IWebDriver, bool> ElementIsVisibleAndEnabled(IWebElement element)
{
return (driver) =>
{
try
{
return element.Displayed && element.Enabled;
}
catch (Exception)
{
// If element is null, stale or if it cannot be located
return false;
}
};
}
The problem is, that you've found an element that is not graphically displayed in the web browser - location property has value: X=0 and Y=0; so you've probably located a wrong element.
This error message...
Javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite
...implies that the WebDriver instance was unable to find the desired element using the Locator Strategy for one or the other reasons:
The locator strategy doesn't identifies the desired element uniquely within the DOM Tree.
The element haven't loaded properly when you tried to interact with it.
Element is within an <iframe> / <frame>
The style attribute of the element contains display: none;
Element is within an shadow DOM.
Analysis
The relevant HTML would have been helpful to analyze the issue in a better way. However, you need to take care of a couple of things as follows:
Ensure that the locator strategy identifies the desired element uniquely within the HTML DOM.
Induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:
cssSelector:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("elementCssSelector"))).click();
xpath:
new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("elementXpath"))).click();
If the WebElement is within an <iframe> / <frame> you need to induce WebDriverWait for the desired frameToBeAvailableAndSwitchToIt().
You can find a relevant detailed discussion in Is it possible to switch to an element in a frame without using driver.switchTo().frame(“frameName”) in Selenium Webdriver Java?
References
You can find a couple of relevant detailed discussions in:
javascript error: Failed to execute 'elementsFromPoint' on 'Document': The provided double value is non-finite
I have also faced the same issue. In my case the problem was that the element I tried to move to wasn't visible yet in the browser.
So I used time.sleep(1)
After that it worked.
This error appeared when I upgraded to ChromeDriver 88 from a version in the 70s (71?). It was actually caused by a workaround from that earlier version. This was using a dropdown in angular. Instead of clicking on an element I had to move to the element and then click on it in separate steps. When I removed the moveToElement steps the error went away
previous code
masterPage.MasterDropDown.click();
Thread.sleep(3000);
actions.moveToElement(masterPage.MasterDropDown).perform();
Thread.sleep(1000);
actions.moveToElement(masterPage.DropdownButton1).perform();
Thread.sleep(1000);
masterPage.DropdownButton1.click();
Was changed to
masterPage.MasterDropDown.click();
masterPage.DropdownButton1.click();
The error went away and it is cleaner.

Selenium Chrom driver : failed to parse value of getElementRegion

I try to implement some Automated User Test with Behat/Mink on Selenium in a Docker.
However, I received a "failed to parse value of getElementRegion" for some Element.
Do you have any clue where I should look to solve this problem ?
I try to launch this test with docker, on a Selenium's Container.
The Behat test try to access to a div inside a modal.
I can confirm that the text is visible on the screen, it's one of my previous line in the behat's file.
I wanted to try the solution describe here, however I don't have any conf.js in my project.
I try to see during the test if the id change (With a sleep juste before trying to click), however, I can manually see it.
I don't see any other solution that the one I linked before on Google.
My Script
#javascript #second
Feature: Builder Features
In Order to use the website as an Builder
I should be able to modify the roadmap
Scenario: I can do click on the modal
When I am on "/thispage"
Then I should see "The Title who open the Modal"
Then I click on ".form-check-label"
Then I wait "1"
Then I wait until "#generic-modal" load
Then I should see "The title of the modal"
Then I should see "The description of the modal"
Then I click on "#check47"
Then I press "Close the modal"
The PHP behind I click on :
/**
* #Then /^I click on "([^"]*)"$/
*/
public function iClickOn($selector)
{
$page = $this->getSession()->getPage();
$element = $page->find('css', $selector);
if (empty($element)) {
throw new Exception("No html element found for the selector ('$selector')");
}
$element->click();
}
The docker-compose's Selenium part
selenium:
image: selenium/standalone-chrome-debug:latest
networks:
app_tier:
ipv4_address: 172.11.1.4
environment:
- SCREEN_WIDTH=1920
- SCREEN_HEIGHT=1080
ports:
- "5900:5900"
volumes:
- "/dev/shm:/dev/shm"
- "../features/file:/usr/share/tag/file/"
The Behat's Extension in behat.yml
extensions:
Behat\MinkExtension:
base_url: "http://172.11.1.3"
sessions:
javascript:
selenium2:
capabilities: {"browserName": "chrome", "browser": "chrome", 'chrome': {'switches': ['--whitelisted-ips']}, "marionette": true, "extra_capabilities": {"goog:chromeOptions":{"w3c":false,"args":["start-maximized", 'disable-dev-shm-usage', 'disable-extensions']}}}
wd_host: 'http://172.11.1.4:4444/wd/hub'
Behat\Symfony2Extension: ~
I should pass all the behat's script without any error.
However, this message appears :
Then I click on "#check27" # FeatureContext::iClickOn()
unknown error: failed to parse value of getElementRegion
(Session info: chrome=77.0.3865.75)
(Driver info: chromedriver=77.0.3865.40 (f484704e052e0b556f8030b65b953dce96503217-refs/branch-heads/3865#{#442}),platform=Linux 4.19.23-coreos-r1 x86_64) (WebDriver\Exception\UnknownError)

How to wait for loading to disappear and then click in the button using protractor (error element not clickable)

I have to click at the button using protractor and GoogleDrive, but the problem is I have a loading before this click. So I have to wait for the loading disappear and then I could click at the button.
The error protractor keep me given is:
The error is:
Element ... is not clickable at point (111, 145). Other element would receive the click: ...
(Session info: chrome=61.0.3163.100)
(Driver info: chromedriver=2.33.506120 (e3e53437346286c0bc2d2dc9aa4915ba81d9023f),platform=Windows NT 10.0.14393 x86_64)
I already tried to maximize the window using browser.driver.manage().window().maximize();
but it didn't work
The loading's xpath is:
/html/body/application/app-loading/loading/div/section/div
I tried use
browser.wait(EC.elementToBeclickable(element), 1000))
but it didn't work too because the element is clickable and visible but there is the loading.
I've tried with no success.
browser.actions().mouseMove(btnNovo).perform().then( () => {
btnNovo.click().then(() => {
What other options do I have?
First use, waiting invisiblity of the element for number of TimeoutMiliseconds:
browser.wait( EC.invisibilityOf( $('#selector') ), TimeoutMiliseconds );
And then for clicking if you want to click at the correct point javascript executor always helps:
browser.executeScript("arguments[0].click()",element);