New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Click does not work in a specific environment #70

Open
AntiPaste opened this Issue Jun 7, 2017 · 6 comments

Comments

Projects
None yet
5 participants
@AntiPaste
Copy link

AntiPaste commented Jun 7, 2017

I am having an issue with getting the chromedp.Click action to work. It seems to work fine when running in headless mode but without headless mode the click does not register at all. Nothing happens in the browser when the click is supposedly made and chromedp just continues on to the next action in the task list.

I am running Arch Linux using LightDM display manager and bspwm window manager. The exact same program was confirmed working correctly on a coworker's machine running Linux Mint 18 Cinnamon and on both Chromium 57 and 61.

Below is some version information and the debug log from chromedp, I am using the current master branch of chromedp (commit 91303cb).

~  ▸ chromium --version
Chromium 59.0.3071.86
~  ▸ go version
go version go1.8.3 linux/amd64
~  ▸ go env
GOARCH="amd64"
GOBIN=""
GOEXE=""
GOHOSTARCH="amd64"
GOHOSTOS="linux"
GOOS="linux"
GOPATH="/home/branch/go/"
GORACE=""
GOROOT="/usr/lib/go"
GOTOOLDIR="/usr/lib/go/pkg/tool/linux_amd64"
GCCGO="gccgo"
CC="gcc"
GOGCCFLAGS="-fPIC -m64 -pthread -fmessage-length=0 -fdebug-prefix-map=/tmp/go-build214944291=/tmp/go-build -gno-record-gcc-switches"
CXX="g++"
CGO_ENABLED="1"
PKG_CONFIG="pkg-config"
CGO_CFLAGS="-g -O2"
CGO_CPPFLAGS=""
CGO_CXXFLAGS="-g -O2"
CGO_FFLAGS="-g -O2"
CGO_LDFLAGS="-g -O2"
chromedp<- {"id":97,"method":"DOM.performSearch","params":{"query":"#loginForm\\:loginButton"}}
chromedp-> {"id":97,"result":{"searchId":"19084.12","resultCount":1}}
chromedp<- {"id":98,"method":"DOM.getSearchResults","params":{"searchId":"19084.12","fromIndex":0,"toIndex":1}}
chromedp-> {"method":"DOM.setChildNodes","params":{"parentId":65,"nodes":[{"nodeId":77,"parentId":65,"backendNodeId":79,"nodeType":1,"nodeName":"INPUT","localName":"input","nodeValue":"","childNodeCount":0,"children":[],"attributes":["id","loginForm:loginButton","type","submit","name","loginForm:loginButton","value","Sign in","style","display: block; margin: 30px auto; text-align: center; background-color: #69be28; border-color: #69be28; width: 100%;","class","btn btn-lg btn-primary"],"shadowRoots":[{"nodeId":78,"backendNodeId":80,"nodeType":11,"nodeName":"#document-fragment","localName":"","nodeValue":"","childNodeCount":1,"children":[{"nodeId":79,"parentId":78,"backendNodeId":81,"nodeType":3,"nodeName":"#text","localName":"","nodeValue":"Sign in"}],"shadowRootType":"user-agent"}]},{"nodeId":80,"parentId":65,"backendNodeId":82,"nodeType":1,"nodeName":"P","localName":"p","nodeValue":"","childNodeCount":1,"attributes":[]},{"nodeId":81,"parentId":65,"backendNodeId":83,"nodeType":1,"nodeName":"P","localName":"p","nodeValue":"","childNodeCount":1,"attributes":[]}]}}
chromedp-> {"id":98,"result":{"nodeIds":[77]}}
chromedp<- {"id":99,"method":"DOM.getBoxModel","params":{"nodeId":77}}
chromedp-> {"id":99,"result":{"model":{"content":[224,617,1006,617,1006,652,224,652],"padding":[200,602,1030,602,1030,667,200,667],"border":[199,600,1031,600,1031,668,199,668],"margin":[199,555,1031,555,1031,713,199,713],"width":555,"height":45}}}
chromedp<- {"id":100,"method":"Runtime.evaluate","params":{"expression":"(function(a) {\n\t\treturn a[0].offsetParent !== null\n\t})($x('/html[1]/body[1]/div[1]/div[2]/div[2]/form[1]/div[1]/div[3]/input[1]'))","objectGroup":"console","includeCommandLineAPI":true,"returnByValue":true}}
chromedp-> {"id":100,"result":{"result":{"type":"boolean","value":true}}}
chromedp<- {"id":101,"method":"Runtime.evaluate","params":{"expression":"(function(a) {\n\t\ta[0].scrollIntoViewIfNeeded(true);\n\t\treturn [window.scrollX, window.scrollY];\n\t})($x('/html[1]/body[1]/div[1]/div[2]/div[2]/form[1]/div[1]/div[3]/input[1]'))","objectGroup":"console","includeCommandLineAPI":true,"returnByValue":true}}
chromedp-> {"id":101,"result":{"result":{"type":"object","value":[0,0]}}}
chromedp<- {"id":102,"method":"DOM.getBoxModel","params":{"nodeId":77}}
chromedp-> {"id":102,"result":{"model":{"content":[224,617,1006,617,1006,652,224,652],"padding":[200,602,1030,602,1030,667,200,667],"border":[199,600,1031,600,1031,668,199,668],"margin":[199,555,1031,555,1031,713,199,713],"width":555,"height":45}}}
chromedp<- {"id":103,"method":"Input.dispatchMouseEvent","params":{"type":"mousePressed","x":615,"y":634,"button":"left","clickCount":1}}
chromedp-> {"id":103,"result":{}}
chromedp<- {"id":104,"method":"Input.dispatchMouseEvent","params":{"type":"mouseReleased","x":615,"y":634,"button":"left","clickCount":1}}
chromedp-> {"id":104,"result":{}}
@kenshaw

This comment has been minimized.

Copy link
Contributor

kenshaw commented Jun 18, 2017

Could you share more information about the HTML that was being used? I'll attempt to reproduce and see what the issue is.

What we've found with using chromedp, is that a lot of the bugs like this are timing dependent. If it's running on a faster (or slower) machine, behavior could be different because one needs to wait for Chrome to finish loading the nodes and for those nodes to be sent back to chromedp. We're looking at ways of retrofitting the API to eliminate some of these headaches, but it is difficult do so in a general purpose fashion that is suitable for all environments.

For the version of chrome/headless_shell you're working with and with the machine configuration, it might be necessary to introduce a short delay between mousePressed and mouseReleased, otherwise it may not be registered properly by the DOM. The easiest way to test this would be to copy the code from the Click/MouseClickNode action and introduce a delay.

@pdemacs

This comment has been minimized.

Copy link

pdemacs commented Jul 15, 2017

I faced the same issue with click there is some problem with the coordinates apparently if browser window is less than the screen, coordinates are not translated properly. I was able to get it work with mouseclickxy api with exact coordinates.

@kenshaw

This comment has been minimized.

Copy link
Contributor

kenshaw commented Jul 16, 2017

@pdemacs thanks, appreciate that! Could you share more information about the actual HTML being used / the environment / chrome version / etc where you were able to get it to work and also where you were able to get it to fail? The XY version is actually the low-level version, and it calculates it based on the dimensions of the node being targeted. This just likely means that the calculation being done is not the "correct" calculation, or that the original dimensions are not being interpreted correctly.

@pdemacs

This comment has been minimized.

Copy link

pdemacs commented Jul 16, 2017

html site: https://www.centrumforex.com/
env: Macbook air, OS X Yoesmite 10.10.5
chrome version: 59.0.3071.115
If you navigate to the page given above and try to click "VIEW FULL RATE CARD" by selecting the xpath of button, it does not work. In the log messages one can see that the box dimensions are different than the actual dimensions. This can be checked by monitoring mouse events on console in the opened browser and hovering on the mouse button.
coordinates indicated by console log when used with XY clicks the button.

@ykyuen

This comment has been minimized.

Copy link

ykyuen commented Jan 10, 2018

+1
having the same problem in arch linux, doesn't work even in headless chromium. wonder if it is also related to the XY coordinates of hidpi display?

In addition, i have the scaling factor set for chromium
--force-device-scale-factor=1.5

@chucnorrisful

This comment has been minimized.

Copy link

chucnorrisful commented Aug 29, 2018

+1 Click working fine on my macbook with chrome-canary (headless/head both)
but on Windows Server (a 2core 4GB RAM machine, not that powerful) it's about 20% chance that the click is working. Testing with higher pause times before the click atm.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment