Reputation: 3
Gurus;
I am running the a MobileWeb test on Android and iOS one after another.
With Android, the default context is 'CHROMIUM' and it is running the entire test just fine whether I shifted to 'CHROMIUM' context or not. With iOS, even after shifting to WEBVIEW_1097.1 which is the WebView context name, I am facing the following error message org.openqa.selenium.InvalidArgumentException: The XCUITest driver only supports W3C actions execution in the native context. when the below code was ran
actions.moveToElement(categoryElm).click(categoryElm).build().perform();
Basically, it is like moving to the Element 'categoryElm' and trying to click it, using the Actions class. I am not trying to do any gesture actions. What is the coding approach for this issue to be used to overcome ?
Titbits of code for reproducing the issue:---
WebElement categoryElm = waitingDriver.until(ExpectedConditions.elementToBeClickable(By.xpath(String.format("//a[contains(text(),'%s')]",category))));
doWait(3000);
public Actions actions= = new Actions(driver);
actions.moveToElement(categoryElm).click(categoryElm).build().perform();
Reference: appium issue 1928
I am using the latest JDK 21, recent appium java-client 9.2.3, recent appium 2.11.2 on a mobile device with iOS version 17.6.1 on Mac version Sonama 14.6.1. Test being run on Safari browser
I have tried shifting to 'NATIVE' just before the click() code is being run with no use.
As per the suggestion in the issue#1928 I incorporated the looping in order to shift in to WEB_VIEW, and using SAFARI browser, as below,
This time the script could not go past the first web element locator, and failed doing it.
/**
* context switcher ==> https://github.com/appium/appium/issues/16481
* In our case with iOS 17.6.1 real device, iOS webview is available by adding webviewConnectTimeout capability.
*
* @throws InterruptedException
*/
public void changeDriverContextToWeb() throws InterruptedException {
Thread.sleep(2000);
if (platform.equalsIgnoreCase("Android")) {
Set<String> allContexts = ((AndroidDriver) driver).getContextHandles();//'Set' ensures non duplicate values
System.out.println("Android allContexts = "+allContexts);
for (String context : allContexts) {
if (context.contains("WEBVIEW")) {
System.out.println("Android allcontexts has WEBVIEW");
((AndroidDriver) driver).context(context);
} // if
} // for
System.out.println("Current Android Context="+((SupportsContextSwitching)driver).getContext());
} else { //"iOS"
Integer loopCount = 1;
while (loopCount < 10) { // looping ONLY for 'iOS'
Thread.sleep(10000); // sleep and hope the driver eventually pulls the webview context
Set<String> allContexts = ((IOSDriver) driver).getContextHandles();//Set ensures non duplicate values
System.out.println("iOS allContexts = "+loopCount+", "+allContexts);
for (String context : allContexts) {
if (context.contains("WEBVIEW")) {
System.out.println("iOS allcontexts has WEBVIEW");
((IOSDriver) driver).context(context);
loopCount = 11;//exit 'while', once 'for' is done
} // if
} // for
System.out.println("Current iOS Context="+loopCount+", "+((SupportsContextSwitching)driver).getContext());
loopCount++;
} // while
} // else
}// method
I have to use this Actions class approach because other methods of click() such as WebElement.click()
, JavascriptExecutor are not working for my page.
Upvotes: 0
Views: 156
Reputation: 18
It works for me when using ExecuteScript instead of Actions.moveToElement as following:
WebDriver.ExecuteScript("return arguments[0].scrollIntoView();", webElement)
Hope this can help you!
Upvotes: 0