How to Find an Element That Contains Specific Text in Selenium Webdriver (Python)

How to check whether the element text contains some text with python selenium?

You can wait for element like this :

from selenium.webdriver.support import expected_conditions as EC

wait = WebDriverWait(driver, 10)
element = wait.until(EC.visibility_of_element_located((By.ID, 'someid')))

extract the text like this :

actual_text = element.text

check whether it contains expected text or not like this:

self.assertIn('expected_string_here', actual_text) 

or like this :

print expected_string_here == actual_text

How to find all elements that contains a value in a specific attribute using selenium python

The below xpath

//*[contains(@style,'display: none')]

should represent all the node which are having style as display none.

for this specific div, you can have //* replaced with //div. Something like this :

//div[contains(@style,'display: none')]

sample code :

disp_none = driver.find_element_by_xpath("//*[contains(@style,'display: none')]")

the above list disp_none should contains all the web elements.

Print the size like this :

print(len(disp_none))


Related Topics



Leave a reply



Submit