Reputation: 5396
I want to click on one button in automation using selenium webdriver & Phantom JS. But it is not clicking on button.
HTML Code :
<button id="play" class="next-play"><span>play</span></button>
I tried :
@FindBy(css = "#play")
private WebElement Btnplay;
Btnplay.click();
I also tried :
JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", Btnplay);
Above same things I tried with ID and XPATH as well but not working with phantomJS. It works when I use any browser.
I took screenshots run time and I can see it is not clicking on button.
When I see error in console, It says unable to find element [which is in next page after click on play]. so it seems might be it is clicking but not going to next page.
Note : Website is built using Html/Css and JS. On click on button,it just changes screens by JS.
UPDATE : It is clicking on element and going to next screen. Issue is in next screen there are 4 elements but When I checked via screenshot , It shows only 2 Elements on page. Should I use element visibility wait?
Upvotes: 1
Views: 1169
Reputation: 16201
Since you have not provided detail HTML, I am going to assume that the application is build using some AJAX as well. There are few things, as we all know, become very important when AJAX is involved.
Problems and possible solutions:
driver.findElement()
calldriver.findElement(whatever)
call you want to use Explicit wait and make sure the element state is ready to accept the click and then perform the clickI strongly suspect the last scenario is the case here and you may want to investigate the event triggered by the UI when you manually perform the action or dig into the application code.
Upvotes: 1