По отдельности prints
в моих циклах for правильно печатает элементы, которые я хочу, но у меня возникают трудности с печатью их вместе в одной строке.
#Grabbing text from the first column in the table that contains "Elephant"
for cell in driver.find_elements_by_xpath("//*[contains(text(),'Elephant')]"):
ElepantText = cell.text
print(ElephantText)
#This prints:
#Elephant 1
#Elephant 2
#Elephant 3 etc...which is what I want
for element in driver.find_elements_by_xpath("//[contains(text(),'Elephant')]/following::td[1]/span/select[1]"):
selected = Select(element).first_selected_option
select_text = selected.text
print(select_text)
#This acquires the selected option in the dropdown menu following the cell that contains "Elephant" and prints the selected option which is what I want.
Я пробовал:
print(ElephantText, select_text)
Но это просто возвращает последнее значение в ElephantText и ни один из параметров select_text Selected.
Я также пытался соединить их вместе, используя:
zipped = zip(ElephantText, select_text)
print(zipped)
Но он возвращает это :
<zip object at 'random hexadecimal number'>
Я снова попытался превратить их в списки, но он просто превратил каждую букву в результате в элемент в списке, так что на данный момент у меня нет идей. Приветствуется любое направление.
РЕДАКТИРОВАТЬ
Вот как я хотел бы, чтобы мои результаты выглядели так:
Elephant 1 - Selected
Слон 2 - Выбрано
Слон 3 - Выбрано