Faizawa
Faizawa

Reputation: 98

How to choose available button to be selected on Appium Python

So I'm making a script to automate the test using appium python. I have some buttons here as seen below: enter image description here

The problem is, I want to select a button if the button is available and not fully booked. I need to choose Date first (All the date buttons can be clicked), and then I'm able to choose the available time. When the button is available then I just click the button and the selecting process is over. I don't care which date or time button will be clicked as long as it can search the available one and click it.

I can make it static by choosing the available ones, but I want to make it automatically choose the available button.

I'm using the xpath like this "(//android.view.ViewGroup[@content-desc="date-day-btn"])[2]", and the number is like in an array, so there will be only 7 numbers (as for 1 to 7) for the date button and 6 numbers (as for 1 to 6) for the time button.

how can I make it possible to choose the button?

Please help, thanks!

Upvotes: 0

Views: 764

Answers (1)

Max Daroshchanka
Max Daroshchanka

Reputation: 2978

From the UI screen example, I assume that available buttons are enabled, but not available buttons are disabled.

So this might help, it will find the first enabled element, found by XPATH:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

date_day_element = WebDriverWait(driver, 20).until(
EC.element_to_be_clickable((By.XPATH, '//android.view.ViewGroup[@content-desc="date-day-btn"]')))

date_day_element.click();

and something similar could be performed for the time button.

Upvotes: 1

Related Questions