Home > front end >  Python Selenium find placeholder if it contains
Python Selenium find placeholder if it contains

Time:01-17

At the moment my code is

driver.find_element_by_xpath("//input[@placeholder='phone']").send_keys('000000000000') 

How would I make it so it would find the placeholder if it contained the word "phone", not just finding the exact word like it is at the moment?

Thanks

CodePudding user response:

You can use the contains() function to check if the placeholder attribute contains the word "phone":

Code:

driver.find_element_by_xpath("//input[contains(@placeholder, 'phone')]").send_keys('000000000000')

This will find any input elements with a placeholder attribute that contains the word "phone", rather than just matching the exact string "phone".

  • Related