Skip to content

Commit

Permalink
Merge pull request #382 from aik099/frame-switching-in-selenium3
Browse files Browse the repository at this point in the history
Fixed frame switching by name on Selenium 3
  • Loading branch information
aik099 authored Oct 31, 2024
2 parents a1091b5 + 1a2dbf9 commit 6331c38
Showing 1 changed file with 39 additions and 1 deletion.
40 changes: 39 additions & 1 deletion src/Selenium2Driver.php
Original file line number Diff line number Diff line change
Expand Up @@ -491,7 +491,45 @@ private function getWindowHandleFromName(string $name): string

public function switchToIFrame(?string $name = null)
{
$this->getWebDriverSession()->frame(array('id' => $name));
$frameQuery = $name;

if ($name) {
try {
$frameQuery = $this->getWebDriverSession()->element('id', $name);
} catch (NoSuchElement $e) {
$frameQuery = $this->getWebDriverSession()->element('name', $name);
}

$frameQuery = $this->serializeWebElement($frameQuery);
}

$this->getWebDriverSession()->frame(array('id' => $frameQuery));
}

/**
* Serialize an Web Element
*
* @param Element $webElement Web webElement.
*
* @return array
* @todo Remove once the https://github.com/instaclick/php-webdriver/issues/131 is fixed.
*/
private function serializeWebElement(Element $webElement)
{
// Code for WebDriver 2.x version.
if (class_exists('\WebDriver\LegacyElement') && \defined('\WebDriver\Element::WEB_ELEMENT_ID')) {
if ($webElement instanceof \WebDriver\LegacyElement) {
return array(\WebDriver\LegacyElement::LEGACY_ELEMENT_ID => $webElement->getID());
}

return array(Element::WEB_ELEMENT_ID => $webElement->getID());
}

// Code for WebDriver 1.x version.
return array(
\WebDriver\Container::WEBDRIVER_ELEMENT_ID => $webElement->getID(),
\WebDriver\Container::LEGACY_ELEMENT_ID => $webElement->getID(),
);
}

public function setCookie(string $name, ?string $value = null)
Expand Down

0 comments on commit 6331c38

Please sign in to comment.