click on a button with JQuery

Anik Source

There is somthing wrong with the page I want to test.

My first try: When I clicked manually on a button, then I will be forwarded normally on the next page. When I tried to click on the same button with selenium, then I get an error page "Sorry...something gone wrong...blabla". I think this problem can only solve the developer team of the page.

By book = By.cssSelector("#button\\.buchung\\.continue");
//By book = By.cssSelector("button.buchung.continue");
//By book = By.xpath("//*[@id='button.buchung.continue']");
WebElement element= ConfigClass.driver.findElement(book);;

But I want to try a workaround:

I clicked on the same button with JQuery. I opened my chrome console and execute the button with:


How can I execute this JQuery expression in my selenium code?

I tried this, but without success:

JavascriptExecutor je = (JavascriptExecutor) driver;


answered 6 months ago Guy #1

Use $


answered 6 months ago SP. #2

jQuery("selector") will return you a list. I think you have to call click() on the element at index 0 (Assuming exactly one element satisfies the selector)



answered 6 months ago New contributor #3

You were pretty close. If the cssSelector is uniquely identifying the WebElement you can use the following code block :

By book = By.cssSelector("#button\\.buchung\\.continue");
WebElement element= ConfigClass.driver.findElement(book);
((JavascriptExecutor) driver).executeScript("arguments[0].click();", element);

comments powered by Disqus