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

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?

Related

Missing 'ELEMENT' when using switchTo().frame() in javascript

I'm using selenium webdriver with javascript on Chrome and I'm trying to interact with an input inside an iframe like so:
await driver.switchTo().frame(By.xpath('/html/body/div[1]/div/div/form/ng-form/div/ui-view/div/dqcomponent[3]/ng-form/div[1]/div[1]/iframe/html/body/form/input[1]'));
I am able to use .click() on the element just fine but the above line causes the following error:
(node:4514) UnhandledPromiseRejectionWarning: InvalidArgumentError: invalid argument: missing 'ELEMENT'
I have tried switching to the element using CSS but it produces the same error, how can I properly switch to said iframe?
My webdriver version is ^4.0.0-beta.1 and my chrome driver is ^88.0.0"
await driver.switchTo().frame expects an element not locator
Use it like
Elem = await driver.findElement(By.id("some if"))
await driver.switchTo().frame(Elem)

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

Getting the following error when clicking on Login button with webdriver: Request failed due to element click intercepted

When clicking on the login button using below XPATH getting following error: Request failed due to element click intercepted, see below image of HTML code:
XPATH:
('//*[#id="btnLogin"]');
('//a[#id="btnLogin"]');
('#btnLogin');
('//a[#id="btnLogin"]/text()');
('//a[contains(#id, "btnLogin")]');
('//a[#id="btnLogin" and #class = "big-button lnkbuttonlogin"]');
//*[#id='btnLogin']
//a[#id='btnLogin']
Above locators should work , press F12 . go to elements tab
.Type ctrl +F and search for matching nodes using above locators .
Alternatively , Try clicking using a Javascript .
import org.openqa.selenium.JavascriptExecutor;
String idloc="btnLogin";
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript("document.getElementById('"+idloc+"').click();");

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

Button is not clickable in application and no selenium exception found in console

I'm trying to click on button(which I marked in yellow) using xpath, but it is failing to click and more over no selenium exception found. I tried to click with css selector and ID. Using isdisplayed() - output is true. but with isselected() - output is false.
I Kept Webdriver wait (Visibility, element located, element to be clickable), implicit wait and explicit wait. But nothing is working out.
I'm new to selenium, please help me out
Below are the code
<button id="addNewButton-btnEl" class="x-btn-center" type="button" hidefocus="true" role="button" autocomplete="off" style="height: 19px;">