32
32
import static org .openqa .selenium .testing .drivers .Browser .IE ;
33
33
import static org .openqa .selenium .testing .drivers .Browser .SAFARI ;
34
34
35
+ import java .util .ArrayList ;
35
36
import java .util .List ;
37
+ import java .util .Optional ;
38
+
39
+ import org .assertj .core .api .AssertionsForClassTypes ;
36
40
import org .junit .jupiter .api .BeforeEach ;
37
41
import org .junit .jupiter .api .Test ;
38
42
import org .openqa .selenium .By ;
44
48
import org .openqa .selenium .WaitingConditions ;
45
49
import org .openqa .selenium .WebElement ;
46
50
import org .openqa .selenium .bidi .Input ;
51
+ import org .openqa .selenium .bidi .Script ;
52
+ import org .openqa .selenium .bidi .script .EvaluateResult ;
53
+ import org .openqa .selenium .bidi .script .EvaluateResultSuccess ;
54
+ import org .openqa .selenium .bidi .script .LocalValue ;
55
+ import org .openqa .selenium .bidi .script .WindowProxyProperties ;
47
56
import org .openqa .selenium .interactions .Actions ;
48
57
import org .openqa .selenium .interactions .PointerInput ;
49
58
import org .openqa .selenium .testing .JupiterTestBase ;
@@ -248,17 +257,11 @@ private void navigateToClicksPageAndClickLink() {
248
257
wait .until (titleIs ("XHTML Test Page" ));
249
258
}
250
259
251
- // Error {"type":"error","id":2,"error":"no such element","message":"No element found for shared
252
- // id"}
253
- // TODO: Need to figure out passing script.SharedReference for frames i.e. handleId for the frame
254
- // The main concern is passing in the context for the iframe to run the command in
255
260
@ SwitchToTopAfterTest
256
261
@ Test
257
262
@ NotYetImplemented (SAFARI )
258
263
@ NotYetImplemented (IE )
259
264
@ NotYetImplemented (EDGE )
260
- @ NotYetImplemented (FIREFOX )
261
- @ NotYetImplemented (CHROME )
262
265
void canMoveMouseToAnElementInAnIframeAndClick () {
263
266
driver .get (appServer .whereIs ("click_tests/click_in_iframe.html" ));
264
267
@@ -267,10 +270,34 @@ void canMoveMouseToAnElementInAnIframeAndClick() {
267
270
268
271
WebElement link = driver .findElement (By .id ("link" ));
269
272
270
- // This needs to the browsing context of the frame
271
- input .perform (windowHandle , new Actions (driver ).moveToElement (link ).click ().getSequences ());
273
+ try (Script script = new Script (driver )) {
274
+
275
+ List <LocalValue > arguments = new ArrayList <>();
276
+
277
+ EvaluateResult result =
278
+ script .callFunctionInBrowsingContext (
279
+ driver .getWindowHandle (),
280
+ "() => document.querySelector('iframe[id=\" ifr\" ]').contentWindow" ,
281
+ false ,
282
+ Optional .of (arguments ),
283
+ Optional .empty (),
284
+ Optional .empty ());
285
+
286
+ assertThat (result .getResultType ()).isEqualTo (EvaluateResult .Type .SUCCESS );
287
+ assertThat (result .getRealmId ()).isNotNull ();
272
288
273
- wait .until (titleIs ("Submitted Successfully!" ));
289
+ EvaluateResultSuccess successResult = (EvaluateResultSuccess ) result ;
290
+
291
+ WindowProxyProperties window =
292
+ (WindowProxyProperties ) successResult .getResult ().getValue ().get ();
293
+
294
+ String frameBrowsingContext = window .getBrowsingContext ();
295
+
296
+ input .perform (
297
+ frameBrowsingContext , new Actions (driver ).moveToElement (link ).click ().getSequences ());
298
+
299
+ wait .until (titleIs ("Submitted Successfully!" ));
300
+ }
274
301
}
275
302
276
303
@ Test
0 commit comments