Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
229 views
in Technique[技术] by (71.8m points)

windows - Using Appium and Python for Test Automation with "contains"

I'm working in test automation using Appium. This will run on a Windows machine, and we're using python to drive Appium. I'm able to find the main window for the application that I'm automating using:

ApplicationWindow = self.driver.find_element_by_xpath("//Pane[@ClassName='wcl_manager1']")

Then I need to search that ApplicationWindow for the button I need to press. I only know that the button will include certain text, but will have other text too. If I knew for sure what the text would be, then I could do:

MenuButton = ApplicationWindow.find_elements_by_xpath("//Button[@Name='Hub window']")

but of course I can't.

I've looked through xpath documentation, and figure that the 'contains' part is what I need, but for the life of me I can't get the syntax right.

I've tried multiple options in syntax:

find_elements_by_xpath("//Button[contains(name(), 'Hub']")
find_elements_by_xpath("//Button[contains(@Name='Hub']")
find_elements_by_xpath("//Button[contains(@Name, 'Hub']")

but none seem to be the magic bullet.

Can anyone point me to the right syntax for Python and Appium's "contains" functionality?

Thanks!

question from:https://stackoverflow.com/questions/66056156/using-appium-and-python-for-test-automation-with-contains

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

For Android I use in my elements.yml file

android_hamburger_menu_my_shiny_btn:
  locator: xpath
  selector: //android.widget.Button[contains(@text, 'My Partial Text Here')]

And for iOS:

ios_hamburger_menu_my_shiny_btn:
  locator: xpath
  selector: //*[contains(@name, "My Partial Text Here")]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...