selenium 中 JS原生getElementByXpath
由于前台页面是vue开发<label for="city" class="el-form-item__label" style="width: 140px;">城市</label><input type="text" autocomplete="off" placeholder="请选择" class="el-input__inner" readonly="reado
·
由于前台页面是vue开发
<label for="city" class="el-form-item__label" style="width: 140px;">城市</label>
<input type="text" autocomplete="off" placeholder="请选择" class="el-input__inner" readonly="readonly">
尝试放弃:
#driver.find_element_by_xpath('//*[@id="city"]/div/div/div/input').send_keys(city) # js = "document.getElementById('city').removeAttribute('readonly')" #js = "$('input[id=city]').attr('readonly',false)" 由于元素不是 city不行 # driver.execute_script(js)
代码验证通过:
需要个页面赋值
select_js = """ function getElementByXpath(path) { return document.evaluate(path, document, null, XPathResult.FIRST_ORDERED_NODE_TYPE, null).singleNodeValue; } ele = getElementByXpath(arguments[0]); ele.readOnly = false; ele.value = arguments[1]; """ driver.execute_script(select_js, '//*[@id="city"]/div/div/div/input', '北京')
更多推荐
已为社区贡献1条内容
所有评论(0)