英文:
python selenium add value to attribute named value
问题
driver.execute_script("arguments[0].setAttribute('value', arguments[1])", element, "New York, NY")
英文:
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="">
答案1
得分: 1
以下是已经翻译好的部分:
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')
英文:
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')
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论