How to click on sing up button using java in selenium i am able to open page but not able to click

+1 vote
package TestNG;

import org.openqa.selenium.By;

import org.openqa.selenium.WebDriver;

import org.openqa.selenium.WebElement;

import org.openqa.selenium.chrome.ChromeDriver;

import org.testng.annotations.AfterMethod;

import org.testng.annotations.BeforeMethod;

import org.testng.annotations.Test;

public class Basic {

WebDriver driver;

@BeforeMethod

public void setup() {

System.setProperty("webdriver.chrome.driver","D:\\selenium\\chromedriver.exe");

driver = new ChromeDriver();

driver.manage().window().maximize();

driver.get("https://www.instagram.com/");

}

@AfterMethod

public void after() {

driver.quit();

}

@Test

public void  demo() throws InterruptedException {

Thread.sleep(6000);

WebElement clickOnsingButton=driver.findElement(By.xpath("//body/div[@id='react-root']/section/main/article/div/div/p/a[1]"));

clickOnsingButton.click();

Thread.sleep(6000);

}

}
Sep 17 in Selenium by anonymous
• 410 points
60 views

2 answers to this question.

0 votes
Best answer

For a software testing services company while automating the application we avoid the usage of the Xpaths. We give preferences to the Classname>=Id>=Linktext>=Css and then last preference is given to the Xpath. Please try the code below.

public void clickCancelBtn() {    
webElement = driver.findElement(By.cssselector("button.btn.btn-outline-primary.bold"));
webElement.click(); 
}

Also, Form seems to be written using jquery. We have to look into the other solution if it not working at your end. Please do share your code snippet or error that it throws if it is not working at your end.

answered Sep 17 by Vishal

selected Sep 17 by Jordan
Thank you it work for me
Glad to help!
0 votes

If you know for sure that the element is present, you could try this to simulate the click - if.Click() isn't working

driver.findElement(By.name("submit")).sendKeys(Keys.RETURN);

or

driver.findElement(By.name("submit")).sendKeys(Keys.ENTER);
answered Sep 17 by Jean

Related Questions In Selenium

0 votes
2 answers

How to scroll the Page up or down in Selenium WebDriver? (using java)

JavascriptExecutor jsx = (JavascriptExecutor)driver; jsx.executeScript("window.scrollBy(0,555)", ""); or Action classes ...READ MORE

answered Sep 5 in Selenium by Sri
• 2,970 points
13,507 views
+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
• 18,400 points
2,715 views
0 votes
1 answer

I am not able to generate extent report with screenshot in selenium cucumber java .. Please help me out

Hello @kanikahans, You need to define Extent Report ...READ MORE

answered Aug 23 in Selenium by Niroj
• 66,340 points
301 views
0 votes
1 answer

How to handle Pop-up in Selenium WebDriver using Java

Actually, its pretty simple. Use this code ...READ MORE

answered Apr 5, 2018 in Selenium by nsv999
• 5,520 points
7,549 views
0 votes
2 answers

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,520 points
3,752 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31 in Selenium by Sri
• 2,970 points
4,736 views
0 votes
2 answers

What is the role of TestNG & JUnit frameworks in Selenium?

TestNG and JUnit are test frameworks . it ...READ MORE

answered Sep 4 in Selenium by Sri
• 2,970 points
881 views
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
2,726 views