Issue
So I want to use format to manipulate with timepicker in selenium python.
I have following variable:
time = Element('xpath=//li[contains(text(),"{}:{} PM")]')
And then I try to use format to located the element:
def select_ten_thirty_time(self):
self.time_picker.wait_element_to_be_clickable().click()
self.time.format(10, 30).wait_element_to_be_clickable().click()
But I get this error:
selenium.common.exceptions.NoSuchElementException: \
Message: Unable to locate element: //li[contains(text(),"{}:{} PM")]
EDIT => Added HTML
<li class="react-datepicker__time-list-item
react-datepicker__time-list-item--selected">10:30 PM</li>
Thank you for your help!
Solution
Please use f string like this :
hour = '10'
sec = '30'
time = driver.find_element_by_xpath(f"//li[contains(text(),'{hour}:{sec}') and contains(text(),'PM')]")
You can have same for AM
or PM
.
Answered By - cruisepandey
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.