Jan 11, 2016
0
Level 21
Selenium select iframe
I am using laracasts/Integrated. I would like to focus on stripe iframe. But I can't do it with this package. Has anybody solve this already? My current code
use unops\Models\Project; use unops\Tests\FactoryUser; use Laracasts\Integrated\Extensions\Selenium; use Laracasts\Integrated\Services\Laravel\Application as Laravel;
class BasketCheckoutTest extends Selenium { use Laravel, FactoryUser;
/**
*
*/
public function testUserDonatesToProjectViaStripe()
{
$user = $this->createUser();
$project = factory(Project::class)->create();
//login user
$this->seePageIs('/checkout')
->submitFormFindBy($this->findByXpath("//button[@class='stripe-button-el']"))
->focusFrame("//iframe[@class='stripe_checkout_app']")
->submitFormFindBy($this->findByXpath("//button[@id='submitButton']"));
//pay with stripe
//see thankyou page
//use already created project, user
}
protected function submitFormFindBy($button, $formData = [])
{
foreach ($formData as $name => $value) {
// Weird, but that's what you gotta do. :)
$value = ['value' => [$value]];
$element = $this->findByNameOrId($name);
$tag = $element->name();
if ($tag == 'input' && $element->attribute('type') == 'checkbox') {
$element->click();
} else {
$element->postValue($value);
}
}
$button->submit();
$this->updateCurrentUrl();
return $this;
}
protected function findByXpath($xpath)
{
try {
return $this->session->element('xpath', $xpath);
} catch (NoSuchElement $e) {
throw new InvalidArgumentException(
"Couldn't find an element, with a class attribute of '{$xpath}'."
);
}
}
protected function focusFrame($xpath)
{
try {
return $this->session->frame('xpath', $xpath);
} catch (NoSuchElement $e) {
throw new InvalidArgumentException('No frame found.');
}
}
}
Response error is: WebDriver\Exception\NoSuchElement: Element not found with xpath, //button[@id='submitButton'] Unable to locate element: {"method":"xpath","selector":"//button[@id='submitButton']"}
Please or to participate in this conversation.