如何找到 id 元素的文本,css 和 Java

How Can I get find text of element of id , css with Java

我正在尝试使用 Java(使用 Selenium Webdriver、Junit、testng)编写测试场景。**

@测试

public void clickAllSee(){
    page.myProfilPages().clickSeeAllWriting();  //here is going to where I want to go.

在这个 这也是我的 html

<div class="row title-body no-gutters"><div class="col"><div class="title"><p>Özgeçmişler</p></div></div> <div class="col"><div id="new-resume" class="new-resume-btn"><a target="_blank" class="btn"><i class="material-icons">add</i> <span id="create-resume" class="d-sm-none d-block">Yeni</span> <span id="mobil-create-resume" class="d-sm-block d-none">Yeni Özgeçmiş Oluştur</span></a></div></div></div>

我想获取 "Yeni Özgeçmiş oluştur Button" 的文本,即 "Yeni Özgeçmiş Oluştur" 。当我尝试使用 "cssSelector" 或 "id" 之类的代码时,它不起作用。

    String h = TLDriver.getDriver().findElement(By.cssSelector(".row.load-more-button")).getText(); //here codes give error
   String h = TLDriver.getDriver().findElement(By.id("mobil-create-resume")).getText();


     Assert.assertEquals(h,"Yeni Özgeçmiş Oluştur");   

}

*- 如何使用 **findElement(By. ...) 到达 "Yeni Özgeçmiş Oluştur" 文本?***

失败场景后,控制台给出类似这样的错误;

这是 "csselement" org.openqa.selenium.NoSuchElementException: no such element 的错误:无法定位元素:{"method":"css selector","selector":".row.load-more-button"}

创建新的简历按钮:

(By.XPATH, "//*[text()='Yeni Özgeçmiş Oluştur']")

简历名称输入:

(By.XPATH, "//input[@id='text']")

创建恢复按钮:

(By.XPATH, "//button[@class='btn btn-secondary']")