OrwellHindenberg
OrwellHindenberg

Reputation: 5078

Click on element does not produce expected outcome using selenium webdriver

First the specs, I am writing Selenium Webdriver tests in java for an application written largely in ExtJS and running on the firefox browser v14. The interesting thing is that Selenium can find the element that I want to click, but the click does not seem to be executed or if it is getting executed the desired outcome (a popup appearing) does not happen. I have also verified in Selenium IDE that the element I am looking for (a span element that I locate via Xpath) exists, but in Selenium IDE I run into the same issue of not being able to click on it.

If I manually click on the button the popup window appears asking for what file I want to upload. I have also tried other elements such as the span's parent 'button' element and parent 'em' element and parent 'div' element all with no luck.

What kills me is that I have been writing Selenium Tests for this application for weeks now and always been able to use this method to click on buttons and for this particular button it no longer works.

        WebElement uploadButton = driver.findElement(By.xpath("//span[contains(text(), 'Upload Popup')]"));
    uploadButton.click();

Edit 1: Thought that the code of the button itself might help

<button id="filefield-1158-buttonEl-btnEl" class="x-btn-center" autocomplete="off" role="button" hidefocus="true" type="button" style="background-color: transparent;">

Note the id is the dynamic id created by ExtJS

Upvotes: 1

Views: 1382

Answers (2)

Anand Somani
Anand Somani

Reputation: 801

Try this out:

     driver.findElements(By.xpath("//button[@class='x-btn-center']").click()

or

     driver.findElements(By.xpath("//*[@class='x-btn-center']").click()

Upvotes: 0

asgoth
asgoth

Reputation: 35829

It can be because of lots of reasons. I would suggest that you debug while your test is running.

It is possible to install FireBug in your Selenium Firefox instance:

File file = new File("firebug-1.8.1.xpi");
FirefoxProfile firefoxProfile = new FirefoxProfile();
firefoxProfile.addExtension(file);
firefoxProfile.setPreference("extensions.firebug.currentVersion", "1.8.1"); // Avoid startup screen

WebDriver driver = new FirefoxDriver(firefoxProfile);

I assume you can launch your test via JUnit (in an IDE like Eclipse). Launch your test in debug mode and set a breakpoint just before clicking on the button. Inspect the html code via FireBug then. It might give you a start.

Another posibility is to select the button by css class (By.className) or selector (By.cssSelector):

WebElement uploadButton = driver.findElement(By.className("x-btn-center"));
uploadButton.click();

If there are multiple buttons on the page you would have to use

List<WebElement> buttons = driver.findElements(By.className("x-btn-center"));
WebElement uploadButton = buttons.get(index);
uploadButton.click();

Upvotes: 1

Related Questions