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
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.classname(), by.cssSelector(), by.xpath(), etc. Even if the 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

0 votes
1 answer

How can we use JavaScript Executor to click and enter data to a web element in Selenium?

WebElement element = driver.findElement("abcd")); // Let the ...READ MORE

answered Mar 21 in Selenium by Lakshmi Sarvepalli
+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 It deals with a similar ...READ MORE

answered Jan 13 in Selenium by Karan
• 10,310 points
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
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,890 points
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,890 points
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