Reputation: 255
I have a list and I would like to use a random choice from that list.
subjects = ['Beauty', 'Fashion', 'Hair', 'Nails', 'Skincare & Makeup', 'News']
random_item = random.choice(subjects)
print(random_item)
driver.find_element_by_xpath('//select[@name='input_4']/option[@value='random_item']').click()
I am able to print a random choice but (random_item
) is not working when used inside the driver.find_element_by_xpath
command.
Am I doing something wrong or is there something I should add to it?
Upvotes: 0
Views: 731
Reputation:
You cannot have an identifier be adjacent to a string literal; that is invalid syntax.
If you want to insert values into a string literal, you can use str.format
:
driver.find_element_by_xpath('//select[@name={}]/option[@value={}]'.format(input_4, random_item)).click()
Upvotes: 1