I have a bit of a complicated problem. First off: github.com/tebeka/selenium is the library I am using for chromedriver/selenium. Here is my basic code to start the chromedriver (works):
const (
chromeDriverPath= `chromedriver.exe`
port= 8080
)
service, err := selenium.NewChromeDriverService(chromeDriverPath, port)
if err != nil {
log.Fatal(err)
}
defer service.Stop()
// Connect to the WebDriver instance running locally.
caps := selenium.Capabilities{"browserName": "chrome"}
wd, err := selenium.NewRemote(caps, fmt.Sprintf("http://localhost:%d/wd/hub", port))
if err != nil {
log.Fatal(err)
}
defer wd.Quit()
The problem lies when I run this on a windows server, running Windows Server 2012. This is the part of my code that fails.
for {
_, err := wd.FindElement(selenium.ByXPATH, xpath1)
if err != nil {
fmt.Println("Waiting to get to get to webpage")
time.Sleep(time.Second * 10)
} else {
fmt.Println("Successfully found page.")
fmt.Println("Getting verification token.")
vT, err := wd.FindElement(selenium.ByXPATH, verificationTokenXpath)
if err != nil{
log.Fatal(err)
}
VerifictionToken, err = vT.GetAttribute("value")
if err != nil {
log.Fatal(err)
}
break
}
}
This is a simple block of code to continuously loop until the webdriver is at a specific webpage, in which case it will grab a token. The looping part will work fine, but once it finds the webpage, it will hang, before doing anything else. For example, in the code above: "Successfully found page." will never be printed. To clarify, this will only happen on this specific windows server. If anyone knows the issue, please let me know.
EDIT: The problem has boiled down to this: wd.FindElement is blocking when the element is found. This only happens on specific operating systems such as Windows Server 2012. Does anyone have an suggestions on how to fix? I do need to get the value of a web element, maybe I could parse the html?