While running it is not recognizing the xpath

0 votes

Hi, I am able to find/write xpath for below webelement,but while running the test it is not recognizing it. Tried with both implicitwait and thread.sleep. Can anyone help me to sort this out.

It is a selection list box:
//span[@class='mat-select-placeholder ng-tns-c25-18 ng-star-inserted']

HTML:

<div class="mat-select-value" xpath="1">
<!---->
<span class="mat-select-placeholder ng-tns-c25-18 ng-star-inserted" style="">&nbsp;</span>
<!---->
</div>

Code:
        try {
            
            Thread.sleep(10000);
             JavascriptExecutor js = (JavascriptExecutor)dr;
             js.executeScript("window.scrollTo(0, document.body.scrollHeight)");
                WebElement element1 = wait.until(ExpectedConditions.visibilityOfElementLocated(By.xpath("//div[@class='mat-select-value']//span[@class='mat-select-placeholder ng-tns-c25-18 ng-star-inserted']")));

System.out.println("Yes2");
            Select s=new Select(element1);
            s.selectByIndex(1);
            Thread.sleep(2000);
            System.out.println("Yes3");
        }
        catch(NoSuchElementException e)
        {
            System.out.println("no");
        }
Aug 3, 2020 in Selenium by Avaneesh
• 120 points
2,385 views

1 answer to this question.

0 votes

There are two parts to this. The first is that you need to be sure that your XPath is correct. 

You can probably use a tool like Firefinder (a firefox extension for Firebug) to validate the XPath. 

Navigate to your page and be sure the element you need is present and then hit f12 and go to the FireFinder section. Enter in the XPath you are using and see if it can be found.

Assuming your XPath is correct then you might want to investigate using an explicit wait if for some reason you are waiting on the page element to load.

Example:

   WebDriverWait wait = new WebDriverWait(_driver, 10);
   wait.until(ExpectedConditions.visibilityOf(........));
answered Aug 3, 2020 by Kim

Related Questions In Selenium

+1 vote
2 answers
0 votes
1 answer

What is Xpath and what are the types of it in Selenium Webdriver?

Hi Piyush, XPath is defined as XML path. It is ...READ MORE

answered May 9, 2019 in Selenium by Pratibha
• 3,690 points
5,388 views
0 votes
1 answer

What is the actual conflict while performing click() on web element, and getting an error like element is not clickable at point(x,y)?

Hey @sastry, the error Element is not clickable ...READ MORE

answered Nov 27, 2019 in Selenium by Sirajul
• 59,230 points
3,559 views
0 votes
1 answer
0 votes
1 answer

Impilicit wait vs Explicit wait vs Fluent wait

Implicit wait: Your telling the WebDriver the ...READ MORE

answered Apr 14, 2018 in Selenium by king_kenny
• 3,710 points
4,351 views
+1 vote
4 answers

Need to wait until page is completely loaded - Selenium WebDriver

You can try something like -  new WebDriverWait(firefoxDriver, ...READ MORE

answered Dec 21, 2019 in Selenium by Robin
64,357 views
0 votes
1 answer

Implicit wait & Explicit wait in selenium WebDriver

Implicit Wait:  While loading a web page in ...READ MORE

answered May 24, 2018 in Selenium by Meci Matt
• 9,460 points
1,819 views
0 votes
2 answers

Finding WebDriver element with Class Name in java

The better way to handle this element ...READ MORE

answered Apr 10, 2018 in Selenium by nsv999
• 5,500 points
13,776 views
webinar REGISTER FOR FREE WEBINAR X
REGISTER NOW
webinar_success Thank you for registering Join Edureka Meetup community for 100+ Free Webinars each month JOIN MEETUP GROUP