| 381 | } |
| 382 | |
| 383 | void Preference::pruningValidTexts(const ElementPtr &element) { |
| 384 | if (!element || this->_validTexts.empty()) |
| 385 | return; |
| 386 | bool valid; |
| 387 | const std::string &originalTextOfElement = element->getText(); |
| 388 | valid = !originalTextOfElement.empty() && |
| 389 | this->_validTexts.find(originalTextOfElement) != this->_validTexts.end(); |
| 390 | if (valid) { |
| 391 | element->validText = originalTextOfElement; |
| 392 | } else { |
| 393 | // if we could not find valid text from text, then try to find valid text from content description field. |
| 394 | const std::string &contentDescription = element->getContentDesc(); |
| 395 | valid = !contentDescription.empty() && |
| 396 | this->_validTexts.find(contentDescription) != this->_validTexts.end(); |
| 397 | if (valid) { |
| 398 | element->validText = contentDescription; |
| 399 | } |
| 400 | } |
| 401 | BDLOG("set valid Text: %s ", element->validText.c_str()); |
| 402 | // if we find valid text from text field or content description field, |
| 403 | // and its parent is clickable, then set it as clickable. |
| 404 | if (valid && !element->getParent().expired() |
| 405 | && !element->getParent().lock()->getClickable()) { |
| 406 | BDLOG("%s", "set valid Text set clickable true"); |
| 407 | element->reSetClickable(true); |
| 408 | } |
| 409 | |
| 410 | for (const auto &child: element->getChildren()) { |
| 411 | pruningValidTexts(child); |
| 412 | } |
| 413 | } |
| 414 | |
| 415 | /// According to the given xpath selector, match and return the satisfied elements inside UI page |
| 416 | /// \param outElements A vector storing matched elements |
no test coverage detected