Open turkogluc opened 6 years ago
PhantomJS doesn't support alert boxes.
Also, PhantomJS does not appear to be maintained any longer, so you might consider switching to headless chrome: https://github.com/ariya/phantomjs/issues/15361
Thanks for that quick answer. I was already trying chrome headless but apparently doing something wrong again.
func DriverInit()(err error){
driver = agouti.ChromeDriver(agouti.ChromeOptions("args", []string{"--headless", "--disable-gpu", "--no-sandbox","--disable-xss-auditor"}))
mutex = &sync.Mutex{}
err = nil
if err = driver.Start(); err != nil {
log.Fatal("Failed to start driver:", err)
}
page, err = driver.NewPage(agouti.Browser("chrome"))
if err != nil {
log.Fatal("Failed to open page:", err)
}
return err
}
func BrowserTest(url string,payload string)(bool) {
mutex.Lock()
//time.Sleep(time.Millisecond)
if err := page.Navigate(url); err != nil {
log.Fatal("Failed to navigate:", err)
}
//sectionTitle, err := page.HTML()
//log.Println("file:", sectionTitle)
//
////log.Println(page.Find("#alert").Text())
//
//u,_ := page.URL()
//log.Print("url",u)
state := false
popup,err := page.PopupText()
if err != nil {
log.Print("No pop up:", err)
state = false
}else{
page.ConfirmPopup()
log.Println("yes ", popup)
state = true
}s
mutex.Unlock()
return state
}
The result gives me around %10 percent false positives. I dont get it why it returns true if there is no alert box.
Also When I am trying to use some functions such as Page.Url() or Page.Html() it returns empty string. What could be the reason
Web browsers interactions aren't synchronous. Just like when you interact with a web browser manually, actions like navigating to a URL or clicking take time. For your specific example, you aren't waiting for the page to load. This can be accomplished by waiting for the popup to appear (using Go code or Gomega, see agouti.org for examples) or by setting a non-zero page load timeout.
Also, it looks like you're ignoring errors in both cases that you receive an empty string.
index.html
main.go
I am trying to get pop up text. I tried alert,prompt functions but result does not change. I always get following error:
I dont know if I am doing something wrong or function does not work properly ?