/** * @param $name * @param $count * @return Option */ public function process($name, $count) { $swatch = new Option($name); $optionCount = 0; while ($this->webDriver->elementExists($this->theme->getConfigurableSwatchSelectorXpath($count, ++$optionCount), WebDriver::BY_XPATH)) { $itemOptionElement = $this->webDriver->byXpath($this->theme->getConfigurableSwatchSelectorXpath($count, $optionCount)); $img = null; $available = !$this->webDriver->elementExists($this->theme->getConfigurableSwatchNotAvailableXpath($count, $optionCount), WebDriver::BY_XPATH); if ($this->webDriver->elementExists($this->theme->getConfigurableSwatchImgXpath($count, $optionCount), WebDriver::BY_XPATH)) { $img = $this->webDriver->byXpath($this->theme->getConfigurableSwatchImgXpath($count, $optionCount))->getAttribute('src'); } $swatch->addValue(new SwatchValue(trim($itemOptionElement->getAttribute('title')), $itemOptionElement, $available, $img)); } return $swatch; }
public function process($name, $count) { /* I really do not like this approach. I don't like depending on JS for this data. But my only other option * is to do a recursive iteration over all of the OPTION elements to extract all of the possible options and * that is just craziness. */ $productOption = new Option($name); $jsVals = $this->webDriver->executeScript('return spConfig'); foreach ($jsVals['config']['attributes'] as $attribute) { if ($attribute['label'] == $name) { foreach ($attribute['options'] as $option) { $productOption->addValue(new Value($option['label'], new WebDriverElementProxy($this->webDriver, $this->theme->getConfigurableProductOptionXpath($count, $option['label']), WebDriver::BY_XPATH))); } } } return $productOption; }