|
24 | 24 | import java.util.List;
|
25 | 25 | import java.util.Map;
|
26 | 26 | import java.util.function.Function;
|
27 |
| -import java.util.stream.Collectors; |
28 | 27 | import org.openqa.selenium.WebDriver;
|
29 |
| -import org.openqa.selenium.WebElement; |
30 | 28 | import org.openqa.selenium.WindowType;
|
31 | 29 | import org.openqa.selenium.bidi.BiDi;
|
32 | 30 | import org.openqa.selenium.bidi.Command;
|
|
37 | 35 | import org.openqa.selenium.json.JsonInput;
|
38 | 36 | import org.openqa.selenium.json.TypeToken;
|
39 | 37 | import org.openqa.selenium.print.PrintOptions;
|
40 |
| -import org.openqa.selenium.remote.RemoteWebDriver; |
41 |
| -import org.openqa.selenium.remote.RemoteWebElement; |
42 | 38 |
|
43 | 39 | public class BrowsingContext {
|
44 | 40 |
|
@@ -415,44 +411,10 @@ public RemoteValue locateNode(Locator locator) {
|
415 | 411 | return remoteValues.get(0);
|
416 | 412 | }
|
417 | 413 |
|
418 |
| - public WebElement locateElement(Locator locator) { |
419 |
| - List<RemoteValue> remoteValues = |
420 |
| - this.bidi.send( |
421 |
| - new Command<>( |
422 |
| - "browsingContext.locateNodes", |
423 |
| - Map.of("context", id, "locator", locator.toMap(), "maxNodeCount", 1), |
424 |
| - jsonInput -> { |
425 |
| - Map<String, Object> result = jsonInput.read(Map.class); |
426 |
| - try (StringReader reader = new StringReader(JSON.toJson(result.get("nodes"))); |
427 |
| - JsonInput input = JSON.newInput(reader)) { |
428 |
| - return input.read(new TypeToken<List<RemoteValue>>() {}.getType()); |
429 |
| - } |
430 |
| - })); |
431 |
| - |
432 |
| - List<WebElement> elements = nodeRemoteValueToWebElementConverter(remoteValues); |
433 |
| - return elements.get(0); |
434 |
| - } |
435 |
| - |
436 | 414 | public void close() {
|
437 | 415 | // This might need more clean up actions once the behavior is defined.
|
438 | 416 | // Specially when last tab or window is closed.
|
439 | 417 | // Refer: https://github.com/w3c/webdriver-bidi/issues/187
|
440 | 418 | this.bidi.send(new Command<>("browsingContext.close", Map.of(CONTEXT, id)));
|
441 | 419 | }
|
442 |
| - |
443 |
| - private List<WebElement> nodeRemoteValueToWebElementConverter(List<RemoteValue> remoteValues) { |
444 |
| - return remoteValues.stream() |
445 |
| - .map( |
446 |
| - remoteValue -> { |
447 |
| - WebElement element = new RemoteWebElement(); |
448 |
| - ((RemoteWebElement) element).setParent(((RemoteWebDriver) this.driver)); |
449 |
| - ((RemoteWebElement) element) |
450 |
| - .setFileDetector(((RemoteWebDriver) this.driver).getFileDetector()); |
451 |
| - remoteValue |
452 |
| - .getSharedId() |
453 |
| - .ifPresent(sharedId -> ((RemoteWebElement) element).setId(sharedId)); |
454 |
| - return element; |
455 |
| - }) |
456 |
| - .collect(Collectors.toList()); |
457 |
| - } |
458 | 420 | }
|
0 commit comments