python selenium为名为value的属性添加值

huangapple go评论137阅读模式
英文:

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')

huangapple
  • 本文由 发表于 2023年3月7日 21:01:40
  • 转载请务必保留本文链接:https://go.coder-hub.com/75662319.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定