I am writing some E2E tests with Appium 2, latest XCUITest and Python. I stumbled upon a problem. For some reason, even though I see the element and its Accessibility ID/XPATH (screenshot attached), I am unable to click it as I get the error below:
NoSuchElementError: An element could not be located on the page using the given search parameters.
at XCUITestDriver.doNativeFind
From Appium log:
[47ecfcae][XCUITestDriver@ce2b] Calling AppiumDriver.findElement() with args: ["xpath","//XCUIElementTypeOther[@name=\"Book with Apple Pay\"]","47ecfcae-3a31-4b8f-ae27-c1069597c822"]
[47ecfcae][XCUITestDriver@ce2b] Executing command 'findElement'
[47ecfcae][XCUITestDriver@ce2b] Valid locator strategies for this request: xpath, id, name, class name, -ios predicate string, -ios class chain, accessibility id, css selector
[47ecfcae][XCUITestDriver@ce2b] Waiting up to 0 ms for condition
[47ecfcae][XCUITestDriver@ce2b] Matched '/element' to command name 'findElement'
[47ecfcae][XCUITestDriver@ce2b] Proxying [POST /element] to [POST http://127.0.0.1:8100/session/73449F3A-89E8-4E0F-89C3-2040654549DC/element] with body: {"using":"xpath","value":"//XCUIElementTypeOther[@name=\"Book with Apple Pay\"]"}
[47ecfcae][XCUITestDriver@ce2b] Got response with status 404: {"value":{"error":"no such element","message":"unable to find an element using 'xpath', value '//XCUIElementTypeOther[@name=\"Book with Apple Pay\"]'","traceback":"(\n\t0 WebDriverAgentLib 0x0000000119adf7b0 FBNoSuchElementErrorResponseForRequest + 252\n\t1 WebDriverAgentLib 0x0000000119adf5e0 +[FBFindElementCommands handleFindElement:] + 312\n\t2 WebDriverAgentLib 0x0000000119aa2dd8 -[FBRoute_TargetAction mountRequest:intoResponse:] + 168\n\t3 WebDriverAgentLib 0x0000000119a8c33c __37-[FBWebServer registerRouteHandlers:]_block_invoke + 404\n\t4 WebDriverAgentLib 0x0000000119ac4d18 -[RoutingHTTPServer handleRoute:withRequest:response:] + 168\n\t5 WebDriverAgentLib 0x0000000119ac5808 __72-[RoutingHTTPServer routeMethod:withPath:parameters:request:connection:]_block_invoke + 64\n\t6 libdispatch.dylib 0x0000000180171978 _dispatch_client_callout + 16\n\t7 libdispatch.dyl...
[47ecfcae][W3C] Matched W3C error code 'no such element' to NoSuchElementError
[47ecfcae][XCUITestDriver@ce2b] Encountered internal error running command: NoSuchElementError: An element could not be located on the page using the given search parameters.
Here is my click code and driver configuration.
'ios': (AppiumBy.ACCESSIBILITY_ID, 'Book with Apple Pay'), # tried XPATH as well
def pay_with_apple_pay(self):
self.wait_for_element_to_be_displayed(self.privacy_policy_link[self.os])
self.wait_for_element_clickable(self.change_payment_method_button[self.os]).click()
self.wait_for_element_clickable(self.apple_pay_select[self.os]).click()
self.wait_for_element_clickable(self.book_with_apple_pay_button[self.os]).click()
options = XCUITestOptions()
options.platform_name = 'iOS'
options.platform_version = config['ios']['platform_version']
options.device_name = config['ios']['device_name']
options.automation_name = 'XCUITest'
options.auto_accept_alerts = True
options.no_reset = False
options.is_headless = config['ios']['is_headless']
options.set_capability('showXcodeLog', True)
options.set_capability('appium:maxTypingFrequency', 10)
options.set_capability('simpleIsVisibleCheck', True)
options.set_capability('appium:settings[snapshotMaxDepth]', 62)
options.set_capability('appium:settings[pageSourceExcludedAttributes]', ['visible'])
options.set_capability('appium:settings[customSnapshotTimeout]', 500)
options.set_capability('appium:includeSafariInWebviews', True)
options.set_capability('appium:isInspectable', True)
options.set_capability('appium:webviewConnectTimeout', 9000)
I can find any other element no problem. Not sure why I can’t click Pay with Apple Pay, any info is appreciated.