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

0 votes
Feb 20, 2019 in Selenium by anonymous
419 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, 2019 by nizam

Related Questions In Selenium

+1 vote
1 answer

How can I automate the process of adding iPhone to cart in Flipkart using Selenium(java),Page Object Model and TestNG? Also validate if product is added and available in cart?

Hey check this https://www.edureka.co/community/47160/automate-purchase-adding-book-cart-flipkart-using-selenium? It deals with a similar ...READ MORE

answered Jan 13 in Selenium by Karan
• 8,200 points
785 views
+1 vote
1 answer
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,510 points
1,570 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,870 points
1,501 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,870 points
1,283 views
0 votes
3 answers

How to click the search button using Selenium web driver and Python

You can try with tag. #this code will ...READ MORE

answered Apr 10, 2019 in Selenium by Matin
5,007 views