Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/selenium/4.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何使用selenium和python填充javascript文本框(无send_键)_Python_Selenium_Selenium Chromedriver - Fatal编程技术网

如何使用selenium和python填充javascript文本框(无send_键)

如何使用selenium和python填充javascript文本框(无send_键),python,selenium,selenium-chromedriver,Python,Selenium,Selenium Chromedriver,我想在字段中输入一个值 我通过以下方式找到元素: driver.find_element_by_xpath('//*[@id="cell--gE-Ez1qtyIA"]') 我这样做是为了显示文本并单击: driver.find_element_by_xpath('//*[@id="cell--gE-Ez1qtyIA"]').click() driver.find_element_by_xpath('//*[@id="cell--gE-Ez1qt

我想在字段中输入一个值

我通过以下方式找到元素:

driver.find_element_by_xpath('//*[@id="cell--gE-Ez1qtyIA"]')
我这样做是为了显示文本并单击:

driver.find_element_by_xpath('//*[@id="cell--gE-Ez1qtyIA"]').click()
driver.find_element_by_xpath('//*[@id="cell--gE-Ez1qtyIA"]').text
到目前为止还不错,但当我想向该字段发送值时,我使用了以下代码:

driver.find_element_by_xpath('//*[@id="cell--gE-Ez1qtyIA"]').send_keys('test')

不会发生任何事情,字段值也不会更改

尝试使用
javascriptexecutor
而不是
sendkeys

WebDriver driver = new ChromeDriver();
JavascriptExecutor je = (JavascriptExecutor)driver;
je.executeScript("document.getElementById('IDofElement').setAttribute('value', 'your value here')");

由于我们不知道您试图访问的文本框的性质,因此您可能会遇到这种情况。
send_keys()
适用于您使用的所有文本框。查找以下要点并尝试将其应用于元素:

  • 元素提取不正确,请尝试其他定位器,如id、名称、css\U选择器
  • 元素尚未准备好使用,请显式等待并检查元素的存在性和可见性
  • 示例代码可以使用显式等待:

    wait = WebDriverWait(driver, 10)
    element = wait.until(EC.presence_of_all_elements_located(("xpath", "//*[@id='cell--gE-Ez1qtyIA']")))
    element.send_keys("test")
    

    最好用真实的URL创建最小的工作代码,这样我们就可以运行它并看到这个问题