Magento 2 Documentation  2.3
Documentation for Magento 2 CMS v2.3 (December 2018)
OptgroupselectElement.php
Go to the documentation of this file.
1 <?php
8 
9 use Magento\Mtf\Client\Locator;
10 use Magento\Mtf\Client\ElementInterface;
11 
15 class OptgroupselectElement extends SelectElement
16 {
22  protected $optGroup = 'optgroup[option[contains(.,"%s")]]';
23 
29  protected $optGroupValue = ".//optgroup[@label = '%s']/option[text() = '%s']";
30 
37  public function getValue()
38  {
39  $this->eventManager->dispatchEvent(['get_value'], [(string)$this->getAbsoluteSelector()]);
40 
41  $selectedLabel = parent::getValue();
42  if ($selectedLabel == '') {
43  throw new \Exception('Selected value has not been found in optgroup select.');
44  }
45 
46  $element = $this->find(sprintf($this->optGroup, $selectedLabel), Locator::SELECTOR_XPATH);
47  $value = $this->getData($element);
48  $value .= '/' . $selectedLabel;
49 
50  return $value;
51  }
52 
59  protected function getData(ElementInterface $element)
60  {
61  return trim($element->getAttribute('label'), chr(0xC2) . chr(0xA0));
62  }
63 
70  public function setValue($value)
71  {
72  $option = $this->prepareSetValue($value);
73  $option->click();
74  }
75 
82  protected function prepareSetValue($value)
83  {
84  $this->eventManager->dispatchEvent(['set_value'], [__METHOD__, $this->getAbsoluteSelector()]);
85  list($group, $option) = explode('/', $value);
86  $xpath = sprintf($this->optGroupValue, $group, $option);
87  $option = $this->find($xpath, Locator::SELECTOR_XPATH);
88  return $option;
89  }
90 }
taxRateField find('.mselect-list') .on( 'click.mselect-edit'
Definition: edit.phtml:162
$group
Definition: sections.phtml:16
$value
Definition: gender.phtml:16
$element
Definition: element.phtml:12