使用自动化selenium的send_keys方法输入数字到prompt输入框,输入框内容无法显示
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<a href="javascript:var age =prompt('qqq');document.write(age)" id="prompt">top</a>
</body>
</html>
html代码
import os
from selenium import webdriver
from time import sleep
driver =webdriver.Chrome()
path=os.path.dirname(os.path.abspath(__file__))
driver.get('file:///'+path+'/a.html')
driver.find_element_by_id("prompt").click()
sleep(3)
alert = driver.switch_to.alert
print(alert.text)
alert.send_keys("20")
alert.accept()
sleep(3)
python代码 问题:输入框为什么无法用send_keys正常输入并显示在页面
我测试的是输入框中不显示,但页面上是输出了20
在输入20之前 少了个 click点击输入框的动作吧 不知道是不是这样