MachinePublishers / jBrowserDriver

A programmable, embeddable web browser driver compatible with the Selenium WebDriver spec -- headless, WebKit-based, pure Java
Other
809 stars 143 forks source link

Click() does not work on button implemented with React #223

Open crazyrum opened 7 years ago

crazyrum commented 7 years ago

I executed the following code, where the button is implemented using React. I turned off the headless mode and saw the cursor was moved onto the button but nothing happened. I also tried Actions but still does not work. It works in FireFox when I click it by hand. Any help is appreciated!

List<WebElement> listOfElements = driver.findElementsByTagName("button"); for(WebElement element : listOfElements) { List<WebElement> listOfChildren = element.findElements(By.tagName("span")); for(WebElement child : listOfChildren) { if(child.getText().equals("View more")) { element.click(); driver.pageWait(); Thread.sleep(5000); } } } driver.quit();

prediator commented 7 years ago

is the element you clicked in the browser window or scrolled up. Make sure that it is visible or set the .screen(new Dimension(700, 1000))

crazyrum commented 7 years ago

is the element you clicked in the browser window or scrolled up. Make sure that it is visible or set the .screen(new Dimension(700, 1000))

When I turned off the headless mode, in the popup window I can see the page being automatically scrolled such that the button is visible and the cursor is right over it. Does it mean that it is visible then?

prediator commented 7 years ago

Yes it should be right is the scope of the window and visible to eye.

  1. Try printing the element that you want to click, make sure you are on the correct element. Safer option would be to use xpath

  2. Try to click manually in the popup see if it works

  3. Try with the help of mouse click using selenium library (Actions class)

crazyrum commented 7 years ago

Yes it should be right is the scope of the window and visible to eye.

Try printing the element that you want to click, make sure you are on the correct element. Safer option would be to use xpath

Try to click manually in the popup see if it works

Try with the help of mouse click using selenium library (Actions class)

Thank you. I tried number 1 and 3 and it still does not work. Then I tried number 2, since I pause the thread after every click. I tried to click by hand in the popup, it does not work neither. Does it mean jBrowserDriver does not support React? Or is there anything in the settings I didn't turn on/off? I turned on (to allow) javascript for sure.

crazyrum commented 7 years ago

I just found out that it works on my office laptop. I am using the latest version of Eclipse Luna (on both my laptops), and the JRE I am using is 1.8. Can anyone help me explain what happened?

hollingsworthd commented 7 years ago

Java minor versions (full output from java -version) along with an example html page to reproduce would be helpful. Thanks!

crazyrum commented 7 years ago

Just an update: I now use the following code: ((JavascriptExecutor) driver).executeScript( "arguments[0].click();", button); driver.pageWait(); and update my JRE to jre1.8.0_112 and it works perfectly! I was previously on jre1.8.0_111.