Selector only working after inspecting/selecting element (selenium)

Viewed 130

I work on selenium with java and when I try find element by (ID, xPath, css) all return the same exception:

'Exception in thread "main" org.openqa.selenium.NoSuchElementException: no such element: Unable 
 to locate element: {"method":"css selector","selector":"#City"} '

the element inside form where form inside frame,

when I open Dev Tools in Chrome the execution context is set to top. AND my controls are located within form, that is a different context, not accessible from top. when I change context from top to the second option the controls appear

my question: how can I change the execution context from top to second option by selenium with java so I can locate controls ??

when I use the below code:

    driver.switchTo().frame("name of frame");
    driver.findElement(By.id("City")).sendKeys("arwa");

the below Exception appear:

   Exception in thread "main" org.openqa.selenium.NoSuchWindowException: no such window

HTML CODE

    <iframe name="PegaGadgetIfr" id="PegaGadgetIfr" border="0" frameborder="0" src="about:blank" style="height: 1932px; width: 100%; overflow: hidden;" cd_frame_id_="8428a80be89e4d1b565c0da28ec73cc4"></iframe>

html code

    <input data-template="" data-test-id="20181209133107059972774" data-ctl="[&quot;TextInput&quot;]" type="text" id="City" value="" class="leftJustifyStyle" title="" name="$PpyWorkPage$pAttendanceData$pCity" validationtype="required" placeholder="" maxlength="150" data-changed="false">
0 Answers
Related