Reputation: 105
I am trying to click an element with text "No, Thanks" using below code, I tried various options so far such as
driver.findElementByXPath("//*[contains(text(),'THANKS')]").click();
driver.findElement(By.name("No,THANKS")).click();
driver.findElementByName("No,THANKS").click();
There is no other element with same text. I am using Appium Driver and Samsung device.
Upvotes: 0
Views: 5507
Reputation: 1
Please try this:
driver.findElement(By.xpath("//android.widget.TextView[contains(@text,'No, Thanks')")).click();
Upvotes: 0
Reputation: 193298
Seems you were close. The text No, Thanks contains a ,
character in between which you need to avoid. So effectively you can use either of the following xpath based Locator Strategies:
xpath 1:
driver.findElementByXPath("//*[starts-with(., 'No') and contains(., 'Thanks')]").click();
xpath 2:
driver.findElementByXPath("//*[contains(., 'No') and contains(., 'Thanks')]").click();
Upvotes: 1
Reputation: 425
If it is TextView, you can consider the following
driver.find_element_by_xpath("//android.widget.TextView[@text='No, Thanks']")
Upvotes: 2