Не удается получить текст элемента. Пробовал getText () и getAttribute ("innerHTML") - PullRequest
1 голос
/ 18 мая 2019

Я пытался получить текст ссылки привязки, используя getText () и getAttribute ("innerHTML"), но не смог получить текст. Вот HTML-код:

<tr _ngcontent-c6="">
    <td _ngcontent-c6="" class="text-center0" style="padding-left:25px">ParentText</td>
</tr>
<tr _ngcontent-c6="">
    <td _ngcontent-c6="">&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;</td>
    <td _ngcontent-c6="" class="text-center4" style="text-align: center; color: rgb(111, 156, 7);">
    <a _ngcontent-c6="">$10,000.00</a>
</td>

Я пробовал следующий XPath:

.//*[contains(text(),'ParentText')]/../following-sibling::tr/td[2]/a

Код, который я пробовал:

WebElement childText = driver.findElement(By.xpath(".//*[contains(text(),'ParentText')]/../following-sibling::tr/td[2]/a"));

WebDriverWait wait = new WebDriverWait(driver,20);

wait.until(ExpectedConditions.elementToBeClickable(childText));

PrintStream out = new PrintStream(System.out, true, "UTF-8");
out.println("Currency Selected:" +childText.getText());

также пробовал последнюю строку с

out.println("Currency Selected:" +childText.getAttribute("innerHTML"));

Также попробовал обычную печать.

System.out.println("Currency is : " +childText.getText());

и

System.out.println("Currency is : " +childText.getAttribute("innerHTML"));

Я не получаю ни ошибок, ни вывода текста. Утверждение передается для isDisplayed () для элемента.

    Assert.assertTrue(ChildText.isDisplayed());

1 Ответ

1 голос
/ 18 мая 2019

Попробуйте с textContent.

System.out.println("Currency is : " +childText.getAttribute("textContent"));
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...