0

I am trying to write a Test Scenario with Java ( using Selenium Webdriver, Junit ,testng).**

@Test

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

In this enter image description here Also this is my 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>

I want to get text of "Yeni Özgeçmiş oluştur Button" which is "Yeni Özgeçmiş Oluştur" . When I am trying to use "cssSelector" or "id" like down my codes, its not working.

    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");   

}

*- How Can I reach "Yeni Özgeçmiş Oluştur" text using **findElement(By. ...) ?***

After Fails scenario , console gives like this error;

This is error of "csselement" org.openqa.selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"css selector","selector":".row.load-more-button"}

Uwe Allner
  • 3,399
  • 9
  • 35
  • 49
  • Have you tried with the xpath?Something like:`findElement(By.xpath("//*[@id="mobil-create-resume"]")).getText();`. –  May 03 '20 at 12:02
  • There is no object with the class load-more-button in your html, so it throws an exception. – Johan Tidén May 03 '20 at 12:12

1 Answers1

0

Yeni Özgeçmiş Oluştur Button:

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

Özgeçmiş Name Input:

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

Özgeçmiş Oluştur Button:

(By.XPATH, "//button[@class='btn btn-secondary']")
AomineDaici
  • 635
  • 1
  • 5
  • 13
  • When I used to first time It worked but I wanted test run again . Its not working anymore . Is there any better solution using id , css or classname ? without xpath because if any thing goes wrong or some other tag added in between, then this path will no longer works. Thanks – Uğur Aydın May 03 '20 at 12:32
  • Now searching over the whole page instead of searching in "span" can u try again ? – AomineDaici May 03 '20 at 13:24
  • Same problem with id ,classname or css selector. it gives same problem on the java. When I am trying to search chrome developer tools , its find it. But its not finding with Java , I think that some things blockes to find here on the elements? Because When I wanted to search with id , its find on chrome developer tools but not finding on the Java – Uğur Aydın May 03 '20 at 14:21
  • Can u share link? – AomineDaici May 03 '20 at 15:46
  • The cause of the error is mostly because you do not wait long enough for the button to load – AomineDaici May 04 '20 at 07:07