Using VS/C#/Selenium/.Net 8.0 for a large set of regression tests which work fine on Windows with Chrome, Edge and Firefox.
However not so well on Mac with Safari with which we are using RemoteWebDriver and connecting to a local Mac Mini. Most button clicks work fine but the side menu options are coming back with this error - OpenQA.Selenium.ElementNotInteractableException
A typical to one of the elements is -
body>pop-shell>div>ppo-sidebar>nav>div.top.level1.menu>div>span.invoices-pop.menu-item.btn
I have tried CSS, XPath and other methods but always there same error. I have also tried the following methods, again all the same result.
protected static void ClickElement(By by)
{
try
{
var link = Driver.FindElement(by);
var js = $"window.scroll(0, {link.Location.Y});";
((IJavaScriptExecutor)Driver).ExecuteScript(js);
Driver.FindElement(by).Click();
}
catch (Exception err)
{
WriteToConsole("Error: " + err.Message);
}
}
protected static void FireEvent(By by)
{
try
{
var link = Driver.FindElement(by);
var js = $"window.scroll(0, {link.Location.Y});";
((IJavaScriptExecutor)Driver).ExecuteScript(js);
((IJavaScriptExecutor)Driver).ExecuteScript("arguments[0].click();", link);
}
catch (Exception ex)
{
WriteToConsole("Error: " + ex.Message);
}
}
Driver.FindElement(InvoicePopMenu).Click();
Anyone got any ideas why these fail in Safari on the Mac please but are ok on Windows. Also as I said other clicks etc are working fine on the Mac?
Using VS/C#/Selenium/.Net 8.0 for a large set of regression tests which work fine on Windows with Chrome, Edge and Firefox.
However not so well on Mac with Safari with which we are using RemoteWebDriver and connecting to a local Mac Mini. Most button clicks work fine but the side menu options are coming back with this error - OpenQA.Selenium.ElementNotInteractableException
A typical to one of the elements is -
body>pop-shell>div>ppo-sidebar>nav>div.top.level1.menu>div>span.invoices-pop.menu-item.btn
I have tried CSS, XPath and other methods but always there same error. I have also tried the following methods, again all the same result.
protected static void ClickElement(By by)
{
try
{
var link = Driver.FindElement(by);
var js = $"window.scroll(0, {link.Location.Y});";
((IJavaScriptExecutor)Driver).ExecuteScript(js);
Driver.FindElement(by).Click();
}
catch (Exception err)
{
WriteToConsole("Error: " + err.Message);
}
}
protected static void FireEvent(By by)
{
try
{
var link = Driver.FindElement(by);
var js = $"window.scroll(0, {link.Location.Y});";
((IJavaScriptExecutor)Driver).ExecuteScript(js);
((IJavaScriptExecutor)Driver).ExecuteScript("arguments[0].click();", link);
}
catch (Exception ex)
{
WriteToConsole("Error: " + ex.Message);
}
}
Driver.FindElement(InvoicePopMenu).Click();
Anyone got any ideas why these fail in Safari on the Mac please but are ok on Windows. Also as I said other clicks etc are working fine on the Mac?
Share edited Mar 4 at 7:57 Kev asked Mar 3 at 10:28 KevKev 3906 silver badges27 bronze badges 3- 1 Are you using Core? Which version? Core was developed so code will work without changes in all OS (Windows, MAC, Linux). Not sure from your description if issue is with code or browser. Sometimes adding User-Agent To HTTPClient solves issues like this when using different browsers. – jdweng Commented Mar 3 at 10:47
- Hi jdweng, I have added some more info to my original question, .Net8.0 – Kev Commented Mar 4 at 7:58
- 1 Are you using same browser? (What is User-Agent in HTTP Header) See browserstack/guide/… – jdweng Commented Mar 4 at 10:50
2 Answers
Reset to default 1Take a screenshot or video of the failure so you can see where it has failed on the page.
There are a couple of reasons why you would get that error
- There is a overlay or wrapper blocking the element and you will need to close or remove it
- The element is disabled and you will need to enable it
- The element is not in the viewport so you will need to scroll to it or maximize the window or change the browser resolution - aim to have a consistent browser resolution across all browsers.
I fixed the issue with a moveto command before the click
protected static void MoveToElement(By by, bool clickit)
{
var element = Driver.FindElement(by);
var actions = new Actions(Driver);
actions.MoveToElement(element);
actions.Perform();
if (clickit) ClickElement(by);
}
Now the elements react correctly when clicked.
发布者:admin,转转请注明出处:http://www.yc00.com/questions/1745098825a4611148.html
评论列表(0条)