Home > Software design >  Pls suggest way to click on - Facebook sign up page- CREATE NEW ACCOUNT BUTTON- using selenium java
Pls suggest way to click on - Facebook sign up page- CREATE NEW ACCOUNT BUTTON- using selenium java

Time:06-06

Pls suggest way to click on - Facebook sign up page- CREATE NEW ACCOUNT BUTTON- using selenium java ( Right click is not permitted) I tried using this code-- https://www.facebook.com/--

WebElement element=driver.findElement(By.id("u_0_2_1a"));       

JavascriptExecutor js = (JavascriptExecutor)driver;
js.executeScript("arguments[0].click();", element);

Error: org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":"#u_0_2_1a"}

CodePudding user response:

You are using an Id which can change. Hence its throwing no such element. Please use the xpath as below:

//form//a[@role='button'][contains(.,'Create New Account')]

I just tested it. it works. Below should be your code.

WebElement element=driver.findElement(By.xpath("//form//a[@role='button'][contains(.,'Create New Account')]"));
  • Related