Button doesnt click locator issue


#1

hello

i am trying to click a button on android app and its not clicking
i tried xpath as well as classname but doesnt work the button just doesnt get clicked

i am getting below error in console

org.openqa.selenium.InvalidSelectorException: javax.xml.transform.TransformerException: org.apache.xpath.functions.FuncContains only allows 2 arguments
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: ‘3.14.0’, revision: ‘aacccce0’, time: ‘2018-08-02T20:05:20.749Z’

also below are logs for same

[W3C (db464ac0)] Calling AppiumDriver.findElement() with args: [“xpath”,"//android.widget.TexTview[contains(@resource-id=‘txtIAgreeToTerms’)]",“db464ac0-e1fa-40fd-94a2-45ff2f08b72c”]
[BaseDriver] Valid locator strategies for this request: xpath, id, class name, accessibility id, -android uiautomator
[BaseDriver] Waiting up to 0 ms for condition
[AndroidBootstrap] Sending command to android: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“xpath”,“selector”:"//android.widget.TexTview[contains(@resource-id=‘txtIAgreeToTerms’)]",“context”:"",“multiple”:false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got data from client: {“cmd”:“action”,“action”:“find”,“params”:{“strategy”:“xpath”,“selector”:"//android.widget.TexTview[contains(@resource-id=‘txtIAgreeToTerms’)]",“context”:"",“multiple”:false}}
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command of type ACTION
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Got command action: find
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Finding ‘//android.widget.TexTview[contains(@resource-id=‘txtIAgreeToTerms’)]’ using ‘XPATH’ with the contextId: ‘’ multiple: false
[AndroidBootstrap] [BOOTSTRAP LOG] [debug] Returning result: {“status”:32,“value”:“javax.xml.transform.TransformerException: org.apache.xpath.functions.FuncContains only allows 2 arguments”}
[AndroidBootstrap] Received command result from bootstrap
[MJSONWP] Matched JSONWP error code 32 to InvalidSelectorError
[W3C (db464ac0)] Encountered internal error running command: InvalidSelectorError: javax.xml.transform.TransformerException: org.apache.xpath.functions.FuncContains only allows 2 arguments
[W3C (db464ac0)] at errorFromMJSONWPStatusCode (C:\Program Files (x86)\Appium\resources\app\node_modules\appium-base-driver\lib\protocol\errors.js:786:12)
[W3C (db464ac0)] at Socket.socketClient.on.data (C:\Program Files (x86)\Appium\resources\app\node_modules\appium-android-driver\lib\bootstrap.js:139:18)
[W3C (db464ac0)] at Socket.emit (events.js:182:13)
[W3C (db464ac0)] at addChunk (_stream_readable.js:279:12)
[W3C (db464ac0)] at readableAddChunk (_stream_readable.js:260:13)
[W3C (db464ac0)] at Socket.Readable.push (_stream_readable.js:219:10)
[W3C (db464ac0)] at TCP.onread (net.js:636:20)
[HTTP] <-- POST /wd/hub/session/db464ac0-e1fa-40fd-94a2-45ff2f08b72c/element 400 112 ms - 832


#2

the given xpath is wrong. Change contains(@resource-id=‘txtIAgreeToTerms’) to contains(@resource-id, ‘txtIAgreeToTerms’)


#3

even that doesnt work

org.openqa.selenium.InvalidSelectorException: javax.xml.transform.TransformerException: A location path was expected, but the following token was encountered: ‘txtIAgreeToTerms’
For documentation on this error, please visit: http://seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: ‘3.14.0’, revision: ‘aacccce0’, time: ‘2018-08-02T20:05:20.749Z’


#4

I’m pretty sure that xpath expression are case-sensitive.

Just apply the fix @mykola-mokhnach said to you and double-check the xpath expression capital letters:

//android.widget.TexTview[contains(@resource-id,‘txtIAgreeToTerms’)]
....................^...............................................

TexTview must be TextView. So…

//android.widget.TextView[contains(@resource-id,‘txtIAgreeToTerms’)]

If this element really exists on screen it should be located.

By the way I advice you to use in this case the id location strategy as long your element is located by id. Your code’ll be more meaningful (and fast!) if you declare explicitly the id location strategy. In Appium Java client: By.id("txtIAgreeToTerms")

Best regards