本文整理汇总了PHP中Symfony\Component\DomCrawler\Crawler::selectButton方法的典型用法代码示例。如果您正苦于以下问题:PHP Crawler::selectButton方法的具体用法?PHP Crawler::selectButton怎么用?PHP Crawler::selectButton使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Symfony\Component\DomCrawler\Crawler
的用法示例。
在下文中一共展示了Crawler::selectButton方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setUp
protected function setUp()
{
$this->client = static::createClient();
$this->client->followRedirects(true);
$this->crawler = $this->client->request('GET', self::LOGIN_URL);
$this->loginForm = $this->crawler->selectButton(self::LOGIN_BUTTON)->form();
}
示例2: click
public function click($link, $context = null)
{
if ($context) {
$this->crawler = $this->match($context);
}
if (is_array($link)) {
$this->clickByLocator($link);
return;
}
$anchor = $this->strictMatch(['link' => $link]);
if (!count($anchor)) {
$anchor = $this->crawler->selectLink($link);
}
if (count($anchor)) {
$this->crawler = $this->client->click($anchor->first()->link());
$this->forms = [];
$this->debugResponse();
return;
}
$buttonText = str_replace('"', "'", $link);
$button = $this->crawler->selectButton($buttonText);
if (count($button)) {
$this->submitFormWithButton($button);
$this->debugResponse();
return;
}
$this->clickByLocator($link);
}
示例3: loginUsingFormUser
/**
* Use this function to connect to user in the application using login form
* MORE SLOW, Use connectUser function above instead
*
* @param $username
* @param $password
* @return Client
*/
protected function loginUsingFormUser($username, $password)
{
$this->client = static::createClient();
$this->crawler = $this->client->request('GET', '/login');
$credentials = array('_username' => $username, '_password' => $password);
$form = $this->crawler->selectButton('_submit')->form($credentials);
$this->client->submit($form);
$this->client->followRedirects();
return $this->client;
}
示例4: click
public function click($link, $context = null)
{
if ($context) {
$this->crawler = $this->match($context);
}
if (is_array($link)) {
$this->clickByLocator($link);
return;
}
$anchor = $this->strictMatch(['link' => $link]);
if (!count($anchor)) {
$anchor = $this->getCrawler()->selectLink($link);
}
if (count($anchor)) {
$this->crawler = $this->clientClick($anchor->first()->link());
$this->forms = [];
return;
}
$buttonText = str_replace('"', "'", $link);
$button = $this->crawler->selectButton($buttonText);
if (count($button)) {
$buttonValue = [];
if (strval($button->attr('name')) !== '' && $button->attr('value') !== null) {
$buttonValue = [$button->attr('name') => $button->attr('value')];
}
$this->proceedSubmitForm($button->parents()->filter('form')->first(), $buttonValue);
return;
}
try {
$this->clickByLocator($link);
} catch (MalformedLocatorException $e) {
throw new ElementNotFound("name={$link}", "'{$link}' is invalid CSS and XPath selector and Link or Button");
}
}
示例5: click
public function click($link, $context = null)
{
if ($context) {
$this->crawler = $this->match($context);
}
if (is_array($link)) {
$this->clickByLocator($link);
return;
}
$anchor = $this->strictMatch(['link' => $link]);
if (!count($anchor)) {
$anchor = $this->crawler->selectLink($link);
}
if (count($anchor)) {
$this->crawler = $this->client->click($anchor->first()->link());
$this->forms = [];
$this->debugResponse();
return;
}
$buttonText = str_replace('"', "'", $link);
$button = $this->crawler->selectButton($buttonText);
if (count($button)) {
$this->proceedSubmitForm($button->parents()->filter('form')->first(), [$button->attr('name') => $button->attr('value')]);
return;
}
$this->clickByLocator($link);
}
示例6: click
public function click($link)
{
$link = $this->escape($link);
$anchor = $this->crawler->selectLink($link);
if (count($anchor)) {
$this->crawler = $this->client->click($anchor->first()->link());
$this->debugResponse();
return;
}
$button = $this->crawler->selectButton($link);
if (count($button)) {
$this->submitFormWithButton($button);
$this->debugResponse();
return;
}
\PHPUnit_Framework_Assert::fail("Link or button for '{$link}' was not found");
}
示例7: clickCreateGameButton
private function clickCreateGameButton(Crawler &$crawler, $gameName)
{
$form = $crawler->selectButton(self::CREATE_GAME_BUTTON_NAME)->form();
$form['create_game_form[name]'] = $gameName;
$crawler = $this->getClient()->submit($form);
$this->assertStatusCode(StatusCode::MOVED_TEMPORARILY);
$crawler = $this->getClient()->followRedirect();
$this->assertStatusCode(StatusCode::OK);
}
示例8: assertShoppingListSave
/**
* @param Crawler $crawler
* @param string $label
*/
protected function assertShoppingListSave(Crawler $crawler, $label)
{
$form = $crawler->selectButton('Save and Close')->form(['orob2b_shopping_list_type[label]' => $label]);
$this->client->followRedirects(true);
$crawler = $this->client->submit($form);
$result = $this->client->getResponse();
$this->assertHtmlResponseStatusCodeEquals($result, 200);
$html = $crawler->html();
$this->assertContains('Shopping List has been saved', $html);
}
示例9: clickPlayButton
/**
* @param Crawler $crawler
* @param string $moveValue
* @return Crawler
*/
private function clickPlayButton(Crawler &$crawler, $turnNumber, $moveValue)
{
$button = $crawler->selectButton(self::PLAY_BUTTON_NAME);
$this->assertEquals(1, count($button), 'play button is shown');
$form = $button->form(['player_form[turnNumber]' => $turnNumber, 'player_form[move]' => $moveValue]);
$crawler = $this->getClient()->submit($form);
$this->assertStatusCode(StatusCode::MOVED_TEMPORARILY);
$this->getClient()->followRedirect();
$this->assertStatusCode(StatusCode::OK);
return $crawler;
}
示例10: getForm
/**
* Get the form from the page with the given submit button text.
*
* @param string|null $buttonText
* @return \Symfony\Component\DomCrawler\Form
*/
protected function getForm($buttonText = null)
{
try {
if ($buttonText) {
return $this->crawler->selectButton($buttonText)->form();
}
return $this->crawler->filter('form')->form();
} catch (InvalidArgumentException $e) {
throw new InvalidArgumentException("Could not find a form that has submit button [{$buttonText}].");
}
}
示例11: assertOrderSave
/**
* @param Crawler $crawler
* @param User $owner
*/
protected function assertOrderSave(Crawler $crawler, User $owner)
{
$form = $crawler->selectButton('Save and Close')->form(['orob2b_order_type[owner]' => $owner->getId()]);
$this->client->followRedirects(true);
$crawler = $this->client->submit($form);
$result = $this->client->getResponse();
$this->assertHtmlResponseStatusCodeEquals($result, 200);
$html = $crawler->html();
$this->assertContains('Order has been saved', $html);
$this->assertViewPage($crawler, $owner);
}
示例12: assertSubtotals
/**
* @param Crawler $crawler
* @param null|int $id
*/
protected function assertSubtotals(Crawler $crawler, $id = null)
{
$form = $crawler->selectButton('Save and Close')->form();
$form->getFormNode()->setAttribute('action', $this->getUrl('orob2b_order_subtotals', ['id' => $id]));
$this->client->submit($form);
$result = $this->client->getResponse();
$this->assertJsonResponseStatusCodeEquals($result, 200);
$data = json_decode($result->getContent(), true);
$this->assertArrayHasKey('subtotals', $data);
$this->assertArrayHasKey('subtotal', $data['subtotals']);
}
示例13: click
public function click($link, $context = null)
{
$literal = Crawler::xpathLiteral($link);
if ($context) {
$this->crawler = $this->match($context);
}
$anchor = $this->crawler->filterXPath('.//a[.=' . $literal . ']');
if (!count($anchor)) {
$anchor = $this->crawler->selectLink($link);
}
if (count($anchor)) {
$this->crawler = $this->client->click($anchor->first()->link());
$this->debugResponse();
return;
}
$button = $this->crawler->selectButton($link);
if (count($button)) {
$this->submitFormWithButton($button);
$this->debugResponse();
return;
}
$nodes = $this->match($link);
if (!$nodes->count()) {
throw new ElementNotFound($link, 'Link or Button by name or CSS or XPath');
}
foreach ($nodes as $node) {
$tag = $node->nodeName;
$type = $node->getAttribute('type');
if ($tag == 'a') {
$this->crawler = $this->client->click($nodes->first()->link());
$this->debugResponse();
return;
} elseif ($tag == 'input' && in_array($type, array('submit', 'image')) || $tag == 'button' && $type == 'submit') {
$this->submitFormWithButton($nodes->first());
$this->debugResponse();
return;
}
}
}
示例14: doResponsavelLogin
/**
* Does login with ID and access key.
**/
public function doResponsavelLogin()
{
// get csrf token
$this->crawler = $this->client->request('GET', $this->responsavel_endpoint);
$token = $this->crawler->filter('input[name="csrfmiddlewaretoken"]');
$token = $token->attr('value');
// get form and submit
$form = $this->crawler->selectButton('Acessar')->form();
$this->crawler = $this->client->submit($form, ['matricula' => $this->username, 'chave' => $this->password, 'csrfmiddlewaretoken' => $token]);
// set matricula
$info = $this->crawler->filter('table[class="info"]');
$this->matricula = trim($info->filter('td')->eq(5)->text());
}
示例15: click
public function click($link, $context = null)
{
$literal = Crawler::xpathLiteral($link);
if ($context) {
$this->crawler = $this->match($context);
}
$anchor = $this->crawler->filterXPath('.//a[.=' . $literal . ']');
if (!count($anchor)) {
$anchor = $this->crawler->selectLink($link);
}
if (count($anchor)) {
$this->crawler = $this->client->click($anchor->first()->link());
$this->debugResponse();
return;
}
$button = $this->crawler->selectButton($link);
if (count($button)) {
$this->submitFormWithButton($button);
$this->debugResponse();
return;
}
$nodes = $this->match($link);
if ($nodes->count()) {
foreach ($nodes as $node) {
if ($node->nodeName == 'a') {
$this->crawler = $this->client->click($nodes->first()->link());
$this->debugResponse();
return;
} elseif ($node->nodeName == 'input' && $node->getAttribute('type') == 'submit') {
$this->submitFormWithButton($nodes->first());
$this->debugResponse();
return;
}
}
}
\PHPUnit_Framework_Assert::fail("Link or button for '{$link}' was not found");
}