Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
SelectstoreElement.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Client\Locator;
10 
14 class SelectstoreElement extends SelectElement
15 {
21  protected $storeGroup = 'optgroup[option[contains(.,"%s")]]';
22 
28  protected $website = 'optgroup[following-sibling::optgroup[option[contains(.,"%s")]]]';
29 
35  public function getValue()
36  {
37  $selectedLabel = trim(parent::getValue());
38  $element = $this->find(sprintf($this->website, $selectedLabel), Locator::SELECTOR_XPATH);
39  $value = trim($element->getAttribute('label'));
40  $element = $this->find(sprintf($this->storeGroup, $selectedLabel), Locator::SELECTOR_XPATH);
41  $value .= '/' . trim($element->getAttribute('label'), chr(0xC2) . chr(0xA0));
42  $value .= '/' . $selectedLabel;
43  return $value;
44  }
45 
53  public function setValue($value)
54  {
55  $pieces = explode('/', $value);
56 
57  if (1 == count($pieces)) {
58  $optionLocator = './/option[contains(text(),"' . $pieces[0] . '")]';
59  } else {
60  $optionLocator = './/optgroup[contains(@label,"'
61  . $pieces[0] . '")]/following-sibling::optgroup[contains(@label,"'
62  . $pieces[1] . '")]/option[contains(text(), "'
63  . $pieces[2] . '")]';
64  }
65 
66  $option = $this->context->find($optionLocator, Locator::SELECTOR_XPATH);
67  if (!$option->isVisible()) {
68  throw new \Exception('[' . implode('/', $pieces) . '] option is not visible in store switcher.');
69  }
70  $option->click();
71  }
72 }
taxRateField find('.mselect-list') .on( 'click.mselect-edit'
Definition: edit.phtml:162
$value
Definition: gender.phtml:16
$element
Definition: element.phtml:12