java/selenium - how can I click on an element from a form that pops up on top of the main page? -


at point in automation project, have click on element part of form pops on top of main page (it doesn't go away menus show when hovering on element , disappear) after accessing page , clicking on element brings out form.

i've been trying kinds of solutions suggested in comments other questions, such using offsets , waiting until element became clickable, none worked me.

here's code in current state first field, "name":

try {                 system.out.println("filling in mandatory fields of contact form... ");                 wait.until(expectedconditions.visibilityofelementlocated(by.xpath("//div[@id='jcemediabox-popup-frame']")));                  system.out.println("filling in name... ");                 wait.until(expectedconditions.elementtobeclickable(by.xpath("(//div[@class='formbody']/input)[1]")));                 webelement namefield = driver.findelement(by.xpath("(//div[@class='formbody']/input)[1]"));                 actions.movetoelement(namefield).build().perform();                 actions.movebyoffset(5, 5).build().perform();                 namefield.sendkeys(contactinput[1]);                 namefield.submit();                 system.out.println("filled in name");              } catch (exception e) {                 system.out.println("could not complete actions on: contact form");                 e.printstacktrace();             } 

edit - working code (thanks segalaj):

try {                 system.out.println("filling in mandatory fields of contact form... ");                 wait.until(expectedconditions.visibilityofelementlocated(by.xpath("//iframe[@id='jcemediabox-popup-iframe']")));                 driver.switchto().frame(driver.findelement(by.xpath("//iframe[@id='jcemediabox-popup-iframe']")));                  driver.wait(pauseinseconds);                  system.out.println("filling in name... ");                 wait.until(expectedconditions.elementtobeclickable(by.name("form[name]")));                 driver.findelement(by.name("form[name]")).sendkeys(contactinput[0]);                 system.out.println("filled in name");                  driver.wait(shorterwait);                                 driver.switchto().defaultcontent();                           } catch (exception e) {                 system.out.println("could not complete actions on: contact form");                 e.printstacktrace();             } 

as popup in iframe, need tell webdriver switch iframe:

<webdriver>.switchto().frame(<iframe-webelement>); 

then you'll able access iframe elements.
not forget come main page when you're done frame.

you can find doc here.

hope helps.


Comments