Getting a stale element Exception

+1 vote

                            Utils to select multi select value from drop down 

Can someone please let me know what needs to be done for the second value to be selected from the drop down list.

I assume some change needs to be made in the multiselectdropdown method 

public void multiselectdropdown(By locator,String value)

{

List<WebElement> dropdownoptions = driver.findElements(locator);

int size = dropdownoptions.size();

System.out.println("Get the size of options:"+ size);

String ar[] = value.split(",");


for(int i=0;i<ar.length;i++)

{

for(int j=0;j<dropdownoptions.size();j++)

{

String text = dropdownoptions.get(i).getText();

System.out.println(text);

try

{

if(!text.isEmpty())

{

if(text.equals(ar[i]))

{

System.out.println("Get the options:"+ar[i]);

dropdownoptions.get(j).click();

}

}

}catch(Exception e)

{


}


                Page: in the method calling the same  parameters more than once

public void pipeline(String fieldvalue,String savepipe)

{

elementutils.multiselectdropdown(selectfieldsvalueselection, fieldvalue);

elementutils.multiselectdropdown(selectfieldsvalueselection, fieldvalue);


}


Test Page using the Data Provider and calling the dataprovider in the test class

@DataProvider

public Object[][] dealpipeline()

{

Object data[][] = ExcelUtil.getTestData(AppConstants.Deal_Pipeline_Sheet_Name);

return data;

}

@Test(priority=10,dataProvider="dealpipeline")

public void getdealspipelineinfo(String selectfields,String savepipelineas)

{

dealspage.pipeline(selectfields,  savepipelineas);

}

Sep 16, 2020 in Selenium by sandhya
• 180 points

edited Sep 16, 2020 by Gitika 1,284 views

Hi, @Sandhya,

Could you please mention at which line of your code you are facing the stale element Exception error?

second line - elementutils.multiselectdropdown(selectfieldsvalueselection, fieldvalue);

added the wait before the second line but still the same

Hey, @Sandhya

Okay as you have metioned in getting an exception, but what is the exact exception or error you are facing? Please post that. 

StaleElementReferenceException: stale element reference: element is not attached to the page document

Hi. @sandhya, 

To resolve this type of error, you can try using this code snippet:

bool staleElement = true; 

while(staleElement){

  try{

     driver.FindElement(By.XPath(link_click), 10).Click();

     staleElement = false;


  } catch(StaleElementReferenceException e){

    staleElement = true;

  }

}
does not work

Hello, @Sandhya

Well..instaed of value if u pass as index then it's easy to parameterize that..so the question here is do u really req to pass the values or index is also fine?

Select by index or value

iam not using select over here my tag is div  in the code
Could you please post your code snippet?

No answer to this question. Be the first to respond.

Your answer

Your name to display (optional):
Privacy: Your email address will only be used for sending these notifications.

Related Questions In Selenium

0 votes
1 answer

I am getting Stale element exception when I try to automate angular js - drop down using Selenium with Java

Hey @Dhivya, StaleElementReferenceException is thrown when an ...READ MORE

answered Feb 12, 2020 in Selenium by Sirajul
• 59,230 points
3,515 views
0 votes
1 answer
0 votes
1 answer

I need to find a web element using CSS

The element should be located with any ...READ MORE

answered Apr 13, 2018 in Selenium by nsv999
• 5,500 points
945 views
+1 vote
5 answers

Getting this error: “Element is not clickable at point”

There are 3 possible solutions for this: 1. ...READ MORE

answered Apr 21, 2018 in Selenium by king_kenny
• 3,710 points
83,241 views
+1 vote
2 answers
0 votes
1 answer

Selenium Exception: Element is not visible

Finding the element before locating the one ...READ MORE

answered May 7, 2018 in Selenium by king_kenny
• 3,710 points
7,257 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,767 views
0 votes
2 answers

Problem while using InternetExplorerDriver in Selenium WebDriver

enable trusted connection  in internet explorer by ...READ MORE

answered Aug 31, 2020 in Selenium by Sri
• 3,190 points
9,186 views
0 votes
2 answers

What is the role of TestNG & JUnit frameworks in Selenium?

TestNG and JUnit are test frameworks . it ...READ MORE

answered Sep 4, 2020 in Selenium by Sri
• 3,190 points
2,935 views
0 votes
1 answer

Geo-location microphone camera pop up

To Allow or Block the notification, access using Selenium and you have to ...READ MORE

answered May 11, 2018 in Selenium by Samarpit
• 5,910 points
7,260 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