Как найти элемент GWT, рядом с которым указан текст c - PullRequest
0 голосов
/ 14 июля 2020

Итак, я пытаюсь улучшить свой код и XPATH, и я пытаюсь обрабатывать поле следующим образом:

<div class="h3">Login</div> <div class="Is3WC-spot Is3WC-spotInfo icon xdm icon_information_16 dialogInfoSpot" style="display: none;" aria-hidden="true"><div class="Is3WC-spotRelativeDivPos"> <div class="Is3WC-spotTextMargins">User Name (login) must:<br>- contain at least 3 characters<br>- be shorter than 60 characters</div> <div class="Is3WC-spotClose icon hover xdm icon_delete_minor_white"></div> </div></div> <div class="floatLeft"><div><input type="text" class="dialogTextBox error"></div> <div class="Is3WC-errorLabel">Login is required.</div></div> <div class="dialogInformationIcon iconInformation clickable"></div>

Как лучше создать этот xpath? Ячейка входа

Теперь она работает как: "/html/body/div[8]/div/table/tbody/tr[2]/td[2]/div/div/div/div[2]/div[3]/div[1]/input" и я совсем не горжусь этим ...

И вопрос по WebDriverWait. В topi c Как нажимать на элементы с поддержкой GWT с помощью Selenium и Python один человек порекомендовал мне использовать WebDriverWait, но у меня был собственный метод:

@staticmethod
def clickPerform(driver, xpath):
    counter = 0;
    while True:
        try:
            driver.find_element_by_xpath(xpath).click()
            break
        except ElementClickInterceptedException:
            time.sleep(1)
            if counter == 10:
                Verify.verifyAssert(True, False,"Not able to click ElementClickInterceptedException: " + xpath)
                break
            counter = counter + 1
        except ElementNotInteractableException:
            time.sleep(1)
            if counter == 10:
                Verify.verifyAssert(True, False,"Not able to click ElementNotInteractableException: " + xpath)
                break
            counter = counter + 1

Лучше использовать упомянутый WebDriverWait вместо моего метода? (Думаю да :)) но ищу мнения)

1 Ответ

0 голосов
/ 16 июля 2020

Здесь может быть несколько способов записать xpath относительно текста. Вы можете попробовать

//div[text()='Login is required.']/preceding-sibling::div/input

OR

//div[text()='Login is required.']/parent::div//input[contains(@class,'TextBox')]
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...