Numra Hashmi
Numra Hashmi

Reputation: 3

How to click on 10:00 AM time slot as per the HTML using Python Selenium

HTML:

<a class="btn btn-sm mb-1 text-white bg-success">10:15 AM</a>

Screenshot:

enter image description here

My test includes following cases

Login to ####.live Then click on "My Providers" Then go to "specialties" And finally pick a date to book appointment Here is my code

**from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep
browser = webdriver.Chrome()
driver = webdriver.Chrome('./chromedriver')
url = "https://##.live/"
user_name = "##"
password ="###"
driver.get(url)
sleep(3)
signin_link = driver.find_element_by_link_text("Sign In")
signin_link.click()
sleep(10)
username_elem = driver.find_element_by_name("username")
password_elem = driver.find_element_by_id("password")
username_elem.send_keys(user_name)
password_elem.send_keys(password)
signin_button = driver.find_element_by_xpath('//button[text()="Sign In"]')
signin_button.click()
sleep(4)
tab=choose-provider&categories=EVERYDAY_CARE&state=&languages=ENG"]')
shedule_appointment=driver.find_element_by_xpath('//*[@id="root"]/div/section/div/div/div[3]/div[2]/div[2]/article/div/a')
shedule_appointment.click()
driver.find_element_by_link_text('12:00 AM').click()
confirm_appointment=driver.find_element_by_link_text('Confirm').click()
sleep(3)
from selenium.webdriver.support.ui import Select**

Upvotes: 0

Views: 615

Answers (1)

undetected Selenium
undetected Selenium

Reputation: 193308

To click on the element with text as 10:15 AM you need to induce WebDriverWait for the element_to_be_clickable() and you can use either of the following Locator Strategies:

  • Using LINK_TEXT:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.LINK_TEXT, "10:15 AM"))).click()
    
  • Using XPATH:

    WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//a[text()='10:15 AM']"))).click()
    
  • Note: You have to add the following imports :

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

Upvotes: 0

Related Questions