Как нажать «одну» кнопку из цепочки кнопокPython

Программы на Python
Ответить
Anonymous
 Как нажать «одну» кнопку из цепочки кнопок

Сообщение Anonymous »

Я использую этот фрагмент кода.

Код: Выделить всё

//separate class locator it lists down all elements
class AddToCartItem:
Inventory = "//div[@class='inventory_item']":
Product_Item_Button = "//button[text()='Add to cart']" #This locator contains x numbers of buttons

Код: Выделить всё

//class and methods to perform the job
class AddToCart(BasePage):
def select_item_to_add(self):
//iterate the buttons
for selectItem in self.get_elements(AddToCartItem.Product_Item_Button):
selectItem.click() //The selectItem.click() clicks all the button. how to handle the iteration of the elements in this section to click a random button from the x number of buttons instead of clicking them all.
Ожидается: нужно нажать/выбрать только одну кнопку из итерации x номеров кнопок, а не нажимать их все.
Факт: Это нажимает все кнопки.
Я не знаю, как с этим справиться. Очень ценю вашу помощь.

Подробнее здесь: https://stackoverflow.com/questions/792 ... of-buttons
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «Python»