2

I have selenium test running in a remote server in headless mode using chrome driver. Following step tries to click on a button but the button doesn't get clicked.

Below test step tries to click the element:

action.moveToElement(element).click().build().perform();

Here is the html of the button:

<button class="icon-btn" data-uk-tooltip="" data-ember-action="90"><i class="us -icon-hover us-icon-plus-circle"></i></button>

Any insight why in headless mode the button is not clicked by above test step? would appreciate any ideas.

Chuchoo
  • 823
  • 2
  • 17
  • 36
  • Why are you using Actions class instead of `driver.findElement(by).click();`? Just asking (this method does work in headless mode). – Zoette Dec 06 '16 at 03:55
  • .click() method is not working . So, I thought actions class could help me in this particular scenario. Not any particular reason. The weird thing is there is similar button on the same page and it works fine.It gets clicked with the same code but the second button never gets clicked with the same code. – Chuchoo Dec 06 '16 at 04:27
  • Good news then! The problem might not be related to the headlessness of your test execution. Please provide a larger html sample containing your successful button AND your failful one. Please also provide both selectors you're using for both buttons. – Zoette Dec 06 '16 at 04:48
  • Try clicking the parent node of the button. This worked for me a couple of times. – JDelorean Dec 06 '16 at 10:07
  • oh I know why this is happening. This is happening because some previous step in my test wasn't able to select the dropdown box element which would only activate the button I am trying to click. If the button is not active it won't register the click. Caveat: testing headless is not super friendly to debugging :) – Chuchoo Dec 06 '16 at 14:07

2 Answers2

0

Let's try with this, it will work :

WebDriver driver = new HtmlUnitDriver();
((HtmlUnitDriver) driver).setJavascriptEnabled(true);
Meloman
  • 3,558
  • 3
  • 41
  • 51
0

I suspect this to be an actual Selenium issue. But I manage to solve and stabilize my tests. See Using Selenium, is there another, more reliable, way to use click command on an element in Headless Chrome?