Issue
I am trying to find a specific sentence and the content after it in order to type in a password for a selenium automation project. Basically every time the website is open it requires three random characters of the password at any position my thinking is the easiest way to find which characters are required is to locate a specific sentence "aria-label="Please type the following characters from your password, 1, 2 and 8."
So what ive managed to do so far is locate the phrase "your password," using;
get_source = driver.page_source
search = "your password,"
print(search in get_source)
How would I go about finding the text after the comma
The element where the text is found;
<input type="password" class="pf pf2 ui-keyboard-input-selected vi-activeElement" name="d9ac2374" id="pff1" num="2" onkeyup="checkEntries2(this, event)" ondragstart="return false" onselectstart="return false" tabindex="1" maxlength="1" value="" autocomplete="off" aria-label="Please type the following characters from your password, 2, 3 and 9." aria-labelledby="id_pff1" showmehow="Please type the following characters from your password, 2, 3 and 9. This is password character number 2." aria-invalid="false">
Solution
You should be able to get that info with the following code, providing that element has an ID (which is unique in a valid HTML page):
desired_info = WebDriverWait(browser,10).until(EC.element_to_be_clickable((By.XPATH, "//input[@id='pff1']"))).get_attribute('showmehow').split('your password,')[1].split('.')[0].replace (' and', ',')
You will also need the following imports:
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
Selenium documentation: https://www.selenium.dev/documentation/
If it doesn't work, you can also locate it based on a partial css selector.
Answered By - platipus_on_fire
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.