2

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>
pramod patel
  • 115
  • 1
  • 2
  • 13

3 Answers3

0

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();
jain28
  • 137
  • 5
  • can you explain how can i use the wait(Implicit/Explicit) – pramod patel Oct 30 '15 at 10:22
  • Implicit wait:: driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); here 10 is the number of seconds. Explicit wait: WebElement myDynamicElement = (new WebDriverWait(driver, 10)).until(ExpectedConditions.presenceOfElementLocated(By.id("myDynamicElement"))); For more Information refer to "http://www.seleniumhq.org/docs/04_webdriver_advanced.jsp" – jain28 Oct 30 '15 at 10:36
  • I used the below code also but not working. driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); – pramod patel Oct 30 '15 at 10:38
  • Can you please tell what exception is being thrown? There must be some exception or error message that is displayed in the console. – jain28 Oct 30 '15 at 10:41
  • Exception in thread "main" org.openqa.selenium.WebDriverException: unknown error: Element is not clickable at point (86, 22). – pramod patel Oct 30 '15 at 10:49
  • This error is caused due to 2 reasons: 1)The element is not visible to click. 2)The page is getting refreshed before it is clicking the element. You should refer to this answer on how to solve this problem as wait is not working in your condition, you should try Actions class which is explained here: "http://stackoverflow.com/questions/11908249/debugging-element-is-not-clickable-at-point-error" – jain28 Oct 30 '15 at 10:52
0

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();
debugger89
  • 2,108
  • 2
  • 14
  • 16
0

This worked for me.

WebElement menuButton = driver.findElement(By
                    .cssSelector("button.qui-popover-button:nth-child(2)"));
            menuButton.click();
pramod patel
  • 115
  • 1
  • 2
  • 13