I am using selenium webdriver with Python on IE and the code mentioned below is working fine but I need to make this in a loop. Please suggest. termsName0 may be 2 ,3 4 or N numbers
Code:
Select(self.driver.find_element_by_name("termsName0")).select_by_visible_text("Blank No Text")
Select(self.driver.find_element_by_name("termsName1")).select_by_visible_text("Blank No Text")
Select(self.driver.find_element_by_name("termsName3")).select_by_visible_text("Blank No Text")
You can use try except contract if you do not know the "N".
from selenium.common.exceptions import ElementNotVisibleException, WebDriverException, NoSuchElementException
try:
i = 0
while True:
name = "termsName" + str(i)
Select(self.driver.find_element_by_name(name).select_by_visible_text("Blank No Text")
i +=1
except (ElementNotVisibleException, WebDriverException, NoSuchElementException):
pass
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With