0

I have multiple input boxes on a webpage with the following xPaths:

//*[@id="swatch-visual-options-panel"]/table/tbody/tr[1478]/td[4]/input

//*[@id="swatch-visual-options-panel"]/table/tbody/tr[1480]/td[4]/input

//*[@id="swatch-visual-options-panel"]/table/tbody/tr[1481]/td[4]/input

One of which is empty and all the others have text inside them. As you may have guessed, there are 1481 elements with the previous xPath pattern but I only want to locate the empty one.

How do I go about doing this in Python?

undetected Selenium
  • 151,581
  • 34
  • 225
  • 281
Elbasel
  • 3
  • 3

2 Answers2

1

You'd grab all the trs and then go through them and find empty ones.

trs = driver.find_elements_by_xpath("//*[@id='swatch-visual-options-panel']/table/tbody/tr")
lst=[]
for tr in trs:   
    elem = tr.find_element_by_xpath("/td[4]/input")
    if(len(elem.text)==0):
       lst.append(elem)
Arundeep Chohan
  • 8,523
  • 4
  • 9
  • 28
1

Among the multiple input boxes on the webpage to locate the <input> element without any text you can use the following based Locator Strategy:

//*[@id="swatch-visual-options-panel"]/table/tbody/tr[1481]/td[4]/input[not(contains(text()))]
undetected Selenium
  • 151,581
  • 34
  • 225
  • 281