pramod patel
pramod patel

Reputation: 135

Button click in selenium webdriver - java

Trying to click the button in the web application. I am opening the below page in chrome the page is opening but trying to click the button inside the page but it is not possible.

package example;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.chrome.ChromeDriver;

public class Example {
    public static void main(String[] args) throws InterruptedException {
        System.setProperty("webdriver.chrome.driver",
                "E:/chromedriver_win32/chromedriver.exe");
        WebDriver driver = new ChromeDriver();


        driver.get("http://localhost:4848/sense/app/C%3A%5CUsers%5Cpramod.STAR%5CDocuments%5CQlik%5CSense%5CApps%5Cdailyreportsample/sheet/PTdBnn/state/analysis");
        driver.findElement(
                By.cssSelector("div.qui-buttonset-left ng-scope button.qui-popover-button.qui-dropdown.ng-scope.ng-isolate-scope.qui-button"))
                .click();

        WebElement element = driver.findElement(By.name("a"));

        element.submit();
        driver.quit();
    }

}

I tried with xpath also not getting. My xpath helper displays the below query when i click on the button.

/html[@class='touch-off']/body[@class='qv-client qv-story-disabled qv-sheet-enabled qv-view-sheet']/div[@class='qv-panel-wrap']/div[@id='qv-toolbar-container']/div[@class='ng-scope']/div[@class='qui-toolbar']/div[@class='qui-buttonset-left ng-scope']/button[@class='qui-popover-button qui-dropdown ng-scope ng-isolate-scope qui-button'][2]

HTML code Snippet: of Button

<button class="qui-popover-button qui-dropdown ng-scope ng-isolate-scope qui-button" tid="2fedac" data-ng-disabled="quiModel.isDisabled()" data-ng-class="buttonClasses" data-icon="toolbar-menu" q-title-translation="Toolbar.Menu" data-qva-activate="onClick()" qui-model="globalMenuButton" ng-if="!isSmallDevice" title="Menu"></button>

Upvotes: 2

Views: 2454

Answers (3)

pramod patel
pramod patel

Reputation: 135

This worked for me.

WebElement menuButton = driver.findElement(By
                    .cssSelector("button.qui-popover-button:nth-child(2)"));
            menuButton.click();

Upvotes: 0

debugger89
debugger89

Reputation: 2776

Try the following XPATH locators for the same.

driver.findElement(By.xpath("//button[@class='qui-popover-button qui-dropdown ng-scope ng-isolate-scope qui-button']")).click();

Or

driver.findElement(By.xpath("//button[@title='Menu']")).click();

Upvotes: 0

jain28
jain28

Reputation: 137

Try adding wait(Implicit/Explicit) after the page is loaded and you should modify your css Selector as below:

driver.findElement(By.cssSelector("div[class^='qui-toolbar']>div>button")).click();

Upvotes: 0

Related Questions