0
<div class="mscrm-globalqc-actionsdiv">
<button id="globalquickcreate_save_button_NavBarGloablQuickCreate" class="mscrm-globalqc-actionbutton" button_quickiframe_id="NavBarGloablQuickCreate">Save</button>

I need to click on the above mentioned Save button. Am using Selenium Webdriver and writing it in java language.

6
  • And, what have you tried with? Commented Apr 22, 2015 at 4:14
  • You don't want to use id? Commented Apr 22, 2015 at 4:16
  • driver.findElement(By.id("globalquickcreate_save_button_NavBarGloablQuickCreate")).click(); Commented Apr 22, 2015 at 4:17
  • I tried by id but it says element not found. Commented Apr 22, 2015 at 4:17
  • Obviously you need to give more code for a proper answer. All the answers below are correct with your code snippet. There is something else going on, as stated it could be in a frame or something. Commented Aug 29, 2017 at 22:38

4 Answers 4

2

Give xpath a try. Possible reason could the duplicate id. I would try with the xpath text based search

By byXpath = By.xpath("//button[contains(text(),'Save')]");
WebElement myDynamicElement = (new WebDriverWait(driver, 10))
  .until(ExpectedConditions.presenceOfElementLocated(byXpath ));
myDynamicElement.click();
Sign up to request clarification or add additional context in comments.

4 Comments

@rjt Please try with the explicit wait as shown above
Probably failing somewhere else then
Could you look at the <button> tag again and let me know if there's a case to switch to some frame or anything of that sorts? Cus it's pointing to that only here.
Could be a possibility. The only thing is that can be inside and iframe and if that's the case you need to switchTo the the iframe
1

Its simple, all you need to do is first find the reference to the element that you want to click.

In your case you can use id attribute of element button i.e id="globalquickcreate_save_button_NavBarGloablQuickCreate"

So the code would look like this.

driver.findElement(By.id("globalquickcreate_save_button_NavBarGloablQuickCreate")).click();

~rOhit

Comments

1

code would look like this: Sometimes click() function doesn't work so try using sendKeys()function

driver.findElement(By.id("globalquickcreate_save_button_NavBarGloablQuickCreate")).sendKeys(Keys.ENTER)

Comments

0

You should wait until, save button visible. After that only, you have to click save button.

Steps

1.Create Firefox browser session

2.Navigate to the page and do some operation [ Whatever you wants as per your requirements]

3.Wait until, save button visible

4.Then click save button.

public void buttonClick()
{
WebDriver driver = new FirefoxDriver();
waitForElementInDOM(driver, "globalquickcreate_save_button_NavBarGloablQuickCreate", 15);
WebElement saveButtonElement = driver.findElement(By.id("globalquickcreate_save_button_NavBarGloablQuickCreate"));

if(saveButtonElement.getText().equalsIgnoreCase("Save"))
{
    saveButtonElement.click();  
    System.out.println("Save button clicked ! ! !");
}
else
{
    System.out.println("Element not present");
}
}
-------------------------------------------------------------------------------------

public void waitForElementInDOM(WebDriver driver,String elementIdentifier, long 
timeOutInSeconds) 
{       
    WebDriverWait wait = new WebDriverWait(driver, timeOutInSeconds );
    try
    {
        //this will wait for element to be visible for 15 seconds
        wait.until(ExpectedConditions.visibilityOfElementLocated(By.id(elementIdentifier))); 
    }
    catch(NoSuchElementException e)
    {           
        e.printStackTrace();
    }           
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.