'Python Selenium , how to access to input with xpath?
I'm trying to get to "input" so that I can enter the values, knowing that the value of the ID is constantly changing
<div>
<idms-error-wrapper {^error-type}="errorType" {^idms-error-wrapper-classes}="idmsErrorWrapperClasses"
<div class=" form-element ">
<input errors="{errors}" {^has-errors}="hasErrors" {$value}="value"
{$aria-required}="isRequired" type="text"
class="form-cell form-textbox form-textbox-text form-field"
id="input-1647425309700-0" value="" aria-required="true">
</div>
</idms-error-wrapper>
</div>
Solution 1:[1]
In case 1647425309700 or 1647425309700-0 is variable here you can use something like this:
input_id = 1647425309700
input_xpath = "//input[contains(@id,'"+ str(input_id) +"')]"
driver.find_element(By.XPATH,input_xpath)
Solution 2:[2]
The <id> attribute of the <input> tag, i.e. input-1647425309700-0 is dynamically generated and will change everytime you would access the page afresh. So identify the desired element you can use either of the the following locator strategies:
css_selector:
input.form-cell.form-textbox.form-textbox-text.form-field[id^='input'][aria-required='true'][value]xpath:
//input[@class='form-cell form-textbox form-textbox-text form-field' and starts-with(@id, 'input')][@aria-required='true' and @value]
Reference
You can find a relevant detailed discussion in:
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Prophet |
| Solution 2 | undetected Selenium |
