【问题标题】:Unable to set value in textbox after setting it enabled through javascript通过javascript设置启用后无法在文本框中设置值
【发布时间】:2014-06-03 10:04:03
【问题描述】:

在我的 Selenium(Ruby 绑定)自动化脚本中通过 javascript 执行程序强制启用后,我试图在文本框中设置值。

input_fieldcar1 = browser.find_element(:xpath, "/html/body/div[5]/div/div[3]/div[2]/div[2]/div/div/div/div/div[2]/div[2]/div/div/div/div[2]/div/div/div[5]/div/div[2]/div[2]/div/div/div/div[4]/div/div/div[3]/div/div/input")
browser.execute_script('arguments[0].removeAttribute("disabled");', input_fieldcar1)

我试过了

input_fieldcar1.send_keys"7"

browser.execute_script('arguments[0].setAttribute("innerHTML","1");', input_field1)

但这些都不起作用!

脚本也和平结束,不会抛出错误等。

什么可能丢失/错误?

【问题讨论】:

    标签: javascript ruby selenium automation selenium-webdriver


    【解决方案1】:

    既然是文本框,那么不妨试试value 属性?

    browser.execute_script('arguments[0].value = "1";', input_field1)
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-01-29
      • 1970-01-01
      相关资源
      最近更新 更多