I am trying to automate a dropdown menu that has hours, and my goal is always choose one hour ahead of a current time.
from selenium import webdriver
from selenium.webdriver.remote.webdriver import WebDriver
import time
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from LoginPage import executor_url,session_id
from datetime import date
from datetime import datetime,timedelta
def attach_to_session(executor_url, session_id):
original_execute = WebDriver.execute
def new_command_execute(self, command, params=None):
if command == "newSession":
# Mock the response
return {'success': 0, 'value': None, 'sessionId': session_id}
else:
return original_execute(self, command, params)
# Patch the function before creating the driver object
WebDriver.execute = new_command_execute
driver = webdriver.Remote(command_executor=executor_url, desired_capabilities={})
driver.session_id = session_id
# Replace the patched function with original function
WebDriver.execute = original_execute
return driver
bro = attach_to_session(executor_url, session_id)
bro.get('https://heregoesmywebportaladdress')
today=date.today()
now=datetime.now()+ timedelta(hours=1)
print(date.strftime(now,'%H'))
bro.find_element_by_id("snapshot_scheduler_form_startDate").send_keys(date.strftime(today, '%Y-%m-%d'))
time.sleep(2)
bro.find_element_by_id("snapshot_scheduler_form_startTime_hour").click()
THIS IS WHERE I HAVE NO CLUE HOW TO DO IT.
bro.find_element_by_xpath("/html/body/div[2]/div/div[2]/div[2]/div/div[2]/div/div/div/div[1]/div/div/div/div/div[2]/form/fieldset[1]/div/select[1]/option[13]").click()
time.sleep(2)
these are the options
<select id="snapshot_scheduler_form_startTime_hour" name="snapshot_scheduler_form[startTime][hour]" class="form-control">
<option value="0">00</option>
<option value="1">01</option>
<option value="2">02</option>
<option value="3">03</option>
<option value="4">04</option>
<option value="5">05</option>
<option value="6">06</option>
<option value="7">07</option>
<option value="8">08</option>
<option value="9">09</option>
<option value="10">10</option> ETCD