Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

no way convert to element from javascript (so we can write our own methods that are not yet supported, for example shadow doms) #346

Open
botmike opened this issue Jan 18, 2022 · 5 comments

Comments

@botmike
Copy link

botmike commented Jan 18, 2022

Currently Behat doesnt yet support shadow root / shadow doms (and thus mink/sel2driver cant use), so we're a bit stuck

ie, there is no way of me getting to the button as an element (and using anything that we can do with elements) :

<ion-toolbar class="md in-toolbar>
	#shadow-root (open)
	<ion-button class="in-toolbar">Sign up</ion-button>
		#shadow-root (open)
		<button type="button">::after</button>
		Sign up
	</ion-button>
	<a href>link</a>
</ion-toolbar>

This wouldn't be so bad, if we had a way of returning an element from javascript, since we could do something like:

/**
 * @When I debug
 */
public function debug()
{
	$driver = self::$driver;
	$shardowRoot = $driver->getPage()->find('css', '.md.in-toolbar');
	$selDriver = $driver->getDriver();
	$wdSession = $selDriver->getWebDriverSession();
	if (is_a($shardowRoot, 'Behat\Mink\Element\NodeElement')) {$shardowRoot = $wdSession->element('xpath', $shardowRoot->getXpath());}
	$elId = $shardowRoot->getID();
	$script = 'return arguments[0].shadowRoot';
	$options = array('script' => $script,'args'   => array(array('ELEMENT' => "$elId")));
	$returned = $wdSession->execute($options); //return $wdSession->execute_async($options);
	var_dump($returned);
}

However, this returns an array, like:

array(1) { ["shadow-6066-11e4-a52e-4f735466cecf"]=> string(36) "cee43f68-12e0-4d34-aa07-feb2649a107f" }
This seems to be an internal weddriver id of the element, but there is no way of converting this id in to an element (that I can see)

With a Java implementation of selenium, you can cast the returned js result like this:

WebElement returned = (WebElement) driver.executeScript("return arguments[0].shadowRoot", shardowRoot);

But I cant see a way of getting back to the element once retuned from javascript for mink/sel2driver

@stof
Copy link
Member

stof commented Jan 18, 2022

The code you are writing here deals with the WebdriverSession, not with the Mink API. So you are reporting it to the wrong repository (we don't maintain the WebdriverSession API, we use it)

@botmike
Copy link
Author

botmike commented Jan 18, 2022

Okay, thanks. I thought it was something MinkSelenium2Driver hadn't exposed. (since it seems like returning that internal id would only be useful if there was another method to get the element for that internal id)
Where should I ask for that?

@stof
Copy link
Member

stof commented Jan 18, 2022

The webdriver library we use (and that you are working with when you do ->getWebDriverSession() to access the underlying lib) is https://packagist.org/packages/instaclick/php-webdriver (version 1, as their version 2 is not stable yet)

@botmike
Copy link
Author

botmike commented Jan 20, 2022

It looks like insta click uses xpath most the way though, this is going to be invalid for shadow-roots, I dont see a way now or any time in the future for insta click to support things like shadow root

Selenium does: SeleniumHQ/selenium#5869

I've had some success using pure javascript to click / set / check elements / content exists
But I cant see anyway around trying to automate file uploads, since it cant be done with pure javascript, and thats where selenium comes in useful

I assume MinkSelenium2Driver wont be able to return a web-elements from javascript and wont be able to support shadow-root / shadow-dom any time soon?

@stof
Copy link
Member

stof commented Jan 20, 2022

Well, Mink itself relies on XPath for its driver API as well. So I don't see how this would git in Mink

And I don't see support for shadow root coming anytime soon, as other drivers that don't instrument an actual browser won't support shadow DOM anyway.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants