我试图填写文本字段中的值,然后点击使用selenium + HtmlUnitDriver + Geb的按钮。
以下是我的代码
from winreg import *
def Enable_Protected_Mode():
# SECURITY ZONES ARE AS FOLLOWS:
# 0 is the Local Machine zone
# 1 is the Intranet zone
# 2 is the Trusted Sites zone
# 3 is the Internet zone
# 4 is the Restricted Sites zone
# CHANGING THE SUBKEY VALUE "2500" TO DWORD 0 ENABLES PROTECTED MODE FOR THAT ZONE.
# IN THE CODE BELOW THAT VALUE IS WITHIN THE "SetValueEx" FUNCTION AT THE END AFTER "REG_DWORD".
#os.system("taskkill /F /IM iexplore.exe")
try:
keyVal = r'Software\Microsoft\Windows\CurrentVersion\Internet Settings\Zones\1'
key = OpenKey(HKEY_CURRENT_USER, keyVal, 0, KEY_ALL_ACCESS)
SetValueEx(key, "2500", 0, REG_DWORD, 0)
print("enabled protected mode")
except Exception:
print("failed to enable protected mode")
当我运行上面的代码时,我得到以下异常
import geb.Browser;
import org.openqa.selenium.htmlunit.HtmlUnitDriver;
RoFlow {
def browser = new Browser()
browser.driver = new HtmlUnitDriver()
Browser.drive {
def websiteOpened = false
go "http://www.google.com"
websiteOpened = $(name: "q").isDisplayed()
println websiteOpened // printing true
println $("input",name:"q")
// printing [<input class="lst lst-tbb sbibps" id="lst-ib" maxlength="2048" name="q" autocomplete="off" title="Search" type="text" value="" aria-label="Search" />]
$("input",name:"q").value("Groovy") // throwing exception
$("input",name:"btnG").click()
}
}
如果我做错了,请告诉我。