how can we click on a button using javascript in selenium and if the button does not have id

0 votes
Feb 20 in Selenium by anonymous
115 views
I'm not sure what role JavaScript plays, but I know for certain that there are other Locator techniques that can be used. They are by.name(), by.classname(), by.cssSelector(), by.xpath(), etc. Even if the by.id() is not present, one of these will definately be present. Do let me know if that's the case.

1 answer to this question.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.
0 votes

If button does not have id, you can write locator based on other locators strategies. 

For example here i am using xpath locator then you need to click button by using Java Script executor in following way...

JavascriptExecutor js = (JavascriptExecutor) driver;//create instance of javascript executor to do actions

WebElement nextButton = driver.findElement(By.xpath("//span[contains(text(),'Next')]"));

js.executeScript("arguments[0].click();", nextButton);

answered Feb 21 by nizam

Related Questions In Selenium

+1 vote
1 answer
0 votes
1 answer

How can I click on male tag in facebook using selenium?

There is an approach for locating an ...READ MORE

answered Dec 20, 2018 in Selenium by Nabarupa
34 views
0 votes
1 answer
0 votes
1 answer

How can we take screenshots of tests in Selenium 2 using C#

We can take screenshots using below function ...READ MORE

answered Mar 23, 2018 in Selenium by nsv999
• 5,030 points
109 views
0 votes
1 answer

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,030 points
65 views
0 votes
1 answer
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,130 points
438 views
0 votes
1 answer

How to use such xpath to find web elements

It's much simpler to use: #MyDiv123 > div.super or ...READ MORE

answered Jun 14, 2018 in Selenium by Samarpit
• 5,130 points
51 views
0 votes
3 answers

© 2018 Brain4ce Education Solutions Pvt. Ltd. All rights Reserved.
"PMP®","PMI®", "PMI-ACP®" and "PMBOK®" are registered marks of the Project Management Institute, Inc. MongoDB®, Mongo and the leaf logo are the registered trademarks of MongoDB, Inc.