由于前台页面是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', '北京')

参考https://stackoverflow.com/questions/10596417/is-there-a-way-to-get-element-by-xpath-using-javascript-in-selenium-webdriver

      https://www.cnblogs.com/momoon/p/12325078.html

Logo

前往低代码交流专区

更多推荐