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
296 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.

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
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,110 points
1,009 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
1,154 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
894 views
0 votes
3 answers