Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

python selenium add value to attribute named value

I want to add with python selenium framework, to input tag’s value attribute equals let’s say New York, NY. I guess I need for it, like driver.execute_script("arguments[0].setAttribute('value',arguments[1])",element, value) but do not know how to use it. Any kind of support will be appreciated

<input type="text" role="combobox" aria-owns="react-autowhatever-1" aria-expanded="false" autocomplete="off" aria-autocomplete="list" aria-controls="react-autowhatever-1" class="StyledFormControl-c11n-8-82-0__sc-18qgis1-0 jxPUpE Input-c11n-8-82-0__sc-4ry0fw-0 qODeK react-autosuggest__input" placeholder="Enter an address, neighborhood, city, or ZIP code" aria-label="Search: Suggestions appear below" id="search-box-input" value="">

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

With reference to this code block

driver.execute_script("arguments[0].setAttribute('value',arguments[1])",element, value)

Where element is the input element.

element=driver.find_element(By.CSS_SELECTOR, "input#search-box-input")

value is the text you would like to set here.

value='New York, NY'

So you can write in a single line

driver.execute_script("arguments[0].setAttribute('value',arguments[1])",driver.find_element(By.CSS_SELECTOR, "input#search-box-input"), 'New York, NY')
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading