2
print('start')
from selenium import webdriver
from selenium.webdriver.common.touch_actions import TouchActions
from selenium.webdriver.chrome.service import Service as ChromeService
options = webdriver.ChromeOptions()
options.add_experimental_option("excludeSwitches", ["enable-automation"])
options.add_experimental_option("useAutomationExtension", True)
options.add_experimental_option('w3c', True)
service = ChromeService(executable_path=CHROMEDRIVER_PATH)
driver = webdriver.Chrome(service=service, options=options)
driver.get('https://stackoverflow.com/')
actions = TouchActions(driver)
actions.scroll(0,500).perform()
print('end')

As shown above,when running the code 'actions.scroll',it throws an exception as:

selenium.common.exceptions.WebDriverException: Message: unknown command: Cannot call non W3C standard command while in W3C mode

I don't want to modify the configuration 'w3c' as 'False',is there any other way to use TouchActions in selenium 4? The operating environment is as follows:

  • selenium 4.1.0
  • ChromeDriver 97.0.4692.71
  • Google Chrome 97.0.4692.71
lonlec
  • 23
  • 3
  • please check if this is what you are looking for? https://stackoverflow.com/a/71038411/1801633 – Ram Jun 22 '22 at 03:58

1 Answers1

1

TouchActions has been deprecated as per v8 Appium - https://github.com/appium/java-client/blob/master/docs/v7-to-v8-migration-guide.md#touch-actions

The below code is an example of longpress based on w3Actions

WebElement tc=driver.findElement(By.xpath("Your Xpath"));

PointerInput finger = new PointerInput(PointerInput.Kind.TOUCH, "finger");
Sequence longpress = new Sequence(finger, 1);
longpress.addAction(finger.createPointerMove(Duration.ofMillis(0), 

PointerInput.Origin.viewport(), tc.getLocation().x,tc.getLocation().y));
longpress.addAction(finger.createPointerDown(PointerInput.MouseButton.LEFT.asArg());

longpress.addAction(new Pause(finger,Duration.ofSeconds(3)));longpress.addAction(finger.createPointerUp(PointerInput.MouseButton.LEFT.asArg()));

driver.perform(Arrays.asList(longpress));
 
Ashok kumar Ganesan
  • 1,098
  • 5
  • 20
  • 48
Ram
  • 119
  • 2
  • 3
  • 10