Selenio
Selenio

Reputation: 63

I can't get selenium webdriver to recognize elements on a modal that fades in

I'm testing a form. When I click on a modal, a div modal appears and the background fades out and this new modal fades in that allows you to input information. For some reason selenium won't recognize elements on this modal. Its not listed as an iframe so I'm not sure if I'm suppose to use the switch to.

the modal

<div id="addressModal-20f95ac4-8a83-4c02-862d-a42d60a74b04" class="modal hide fade in" 
style="display: block;" aria-hidden="false">

text are in modal

<textarea rows="2"name="viewModel.MortgageForm.BorrowerInformationSection.Borrowers[0].Dependents.modalTextArea-addressModal-20f95ac4-8a83-4c02-862d-a42d60a74b04" id="modalTextArea-addressModal-20f95ac4-8a83-4c02-862d-a42d60a74b04" cols="20" class="span valid"></textarea>

Upvotes: 1

Views: 2784

Answers (1)

Sensei
Sensei

Reputation: 173

There may be multiple elements with that same DOM signature and webdriver picked up the one which is not context of the current user view.

Solution: Since it is not an iframe, you will have to locate the element in context of the modal box container. You can try the following to locate the textarea webelement:

  1. JQuery:

    $("div[id^='addressModal']:visible").find("textarea")
    
  2. WebDriver(Java):

    driver.findElement(By.cssSelector,"div[id^=addressModal] textarea")
    

Upvotes: 1

Related Questions