How would I index each number in this range and search for it with selenium

Viewed 92

from selenium import webdriver

driver = webdriver.Firefox()

numb = [*range(40, 70, 1)]
print(numb) 

discount2 = driver.find_elements_by_partial_link_text(numb)

Im trying to search for everything in the range using discount 2; whenever I run this function it will search it as the whole thing.

1 Answers

You need to iterate over the numbers one by one:

discount = {} # create empty dict
for number in range(40, 70):
    discount[number] = driver.find_elements_by_partial_link_text(str(number))

Now, the results will be stored in the discount dict using number as the key. I also called str() on number because you'll be searching strings.

Related