I am performing automation on my website using selenium webdriver. I am able to login into website but not able to perform click operation on element. My code attempts are:
WebElement add = BrowserUtilities.driver.findElement(By.xpath("//button[@class = 'btn btn-primary btn-lg']"));
add.click();
I also tried with javascript executor as below :
JavascriptExecutor js = (JavascriptExecutor) BrowserUtilities.driver;
js.executeScript("argument[0].click()", add);
now I am getting exception in console like:
FAILED CONFIGURATION: @BeforeClass launchBrowserTest
org.openqa.selenium.WebDriverException: unknown error: argument is not defined
Please suggest me if any other solution.
It's because of javascript and ajax call present you can try this code :
Find Element using webdriver wait as :
WebDriverWait wait=new WebDriverWait(driver,50 );
WebElement element = wait.until(ExpectedConditions.presenceOfElementLocated(By.xpath("//button[@type='Cancel']")));
Then perfrom click operation using Actions class as :
Actions actions = new Actions(driver);
actions.moveToElement(element).click().build().perfrom();
Try with it.
WebDriverWait wait = new WebDriverWait(driver,9000);
WebElement button=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class = 'btn btn-primary btn-lg']")));
button.click();
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.