Partial text search


#1

I have an element that come up as “foo ” (attribute name) in appium inspector.

I’ve tried using self.wd.find_element_by_id(“foo ”) but getting an error in python…

“SyntaxError: Non-ASCII character ‘\xef’ in file working.py on line 51, but no encoding declared; see http://python.org/dev/peps/pep-0263/ for details”

Is there another partial text search I can do so that I can search for “foo” and I’ll be able to select the element?

Tried using find_elements_by_xpath("//*[contains(text(), ‘foo’)]")

But I’m getting the following error

NameError: global name ‘find_elements_by_xpath’ is not defined

Is there an alternative method I can use?


#2

Was able to resolve this issue after adding the following to the beginning of the file…

#!/usr/bin/env python

-- coding: utf-8 --

now self.wd.find_element_by_id(“foo ”) works


#3

Switch to Python 3 :wink: