-1
<button class="md-trigger btn btn-primary mrg-b-lg" data-toggle="modal" data-target="CaseProcessmodal" id="AddCaseButton" onclick="return validateForm('#CaseProcessmodal');">Add Case</button>

I have an element location like above, trying to click on the button in selenium, its not working. I am using page factory, element id is correctly matching though.

Verified with other matching element id.

undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
RK007
  • 23
  • 1
  • 10
  • 3
    Please format your question and add information like the page source, the code that you've used and what error you're facing. – demouser123 Jun 17 '19 at 10:30

2 Answers2

0

The desired element is within a Modal Dialog so to click() on the element you have to induce WebDriverWait for the elementToBeClickable() and you can use either of the following Locator Strategies:

  • cssSelector:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.cssSelector("button.md-trigger.btn.btn-primary.mrg-b-lg#AddCaseButton[data-target='CaseProcessmodal']"))).click();
    
  • xpath:

    new WebDriverWait(driver, 20).until(ExpectedConditions.elementToBeClickable(By.xpath("//button[@class='md-trigger btn btn-primary mrg-b-lg' and @id='AddCaseButton'][text()='Add Case']"))).click();
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • I have already tried with wait formulae: Utils.scrollIntoView(driver, AddcaseButton); WebDriverWait wait = new WebDriverWait(driver, 30); wait.until(ExpectedConditions.refreshed(ExpectedConditions.elementToBeClickable(AddcaseButton))); its not workign either. Tried giving wait, action etc everything. After click on teh button there would be a processing screen and should close the window. click action is not working atall – RK007 Jun 18 '19 at 12:25
0

I found solution to this putting if condition, agian applied click action. it worked.

RK007
  • 23
  • 1
  • 10