Reputation: 3166
I am trying to process all elements which have text. I know I can iterate over the list and process only those which contain text:
from selenium import webdriver
driver = webdriver.Chrome()
my_elelements = driver.find_elements_by_xpath("//*")
for elm in my_elements:
if elm.text!=""
'processing of text
but is there a quicker way only find elements with text, with selenium's driver.find_elements_by_
without finding all elements and then filtering only those with text...? Is there a wildcard that can be used here ?
Upvotes: 0
Views: 1169
Reputation: 5347
You can use the following x-paths to get all elements with text.
//*[text()]
-- it will returns all element with text including parent nodes//*[text()][count(*)=0]
-- it returns all element with text only child nodesor you can use the following x-path to get the all elements without text.
//*[not(text())]
-- it will returns all element without text including parent nodes//*[not(text())][count(*)=0]
-- it returns all element without text only child nodesUpvotes: 2