Do you have questions ? We got the answers!

Ask a question:

1
Unable to click on the User name searched from the Look up field

Open 1 Answers 24 Views
Unable to click on the User name searched from the Look up field. Tried by giving exclipit wait but not working. Please help me with the code. Attached code is below:

public class AddFollowerTask {
        WebDriver driver ;
        
        public AddFollowerTask(WebDriver driver)
        {
            this.driver = driver;
        }
        
        public void addFollower() {
            driver.findElement(By.xpath("//*[@id=\"crumb-right\"]/ul/li[3]/span[2]/a")).click();
           driver.findElement(By.xpath("//*[@id=\"crumb-right\"]/ul[1]/li[3]/span[2]/div/div[2]/div[1]/div/input")).sendKeys("a");

            try{
                (new WebDriverWait(driver, 6/*sec*/)).
                        until(ExpectedConditions.elementToBeClickable((By.className("clearfix "))));          
                        }
            catch(org.openqa.selenium.TimeoutException e){
                System.out.println(e.getMessage());
            }
            
         List<WebElement> autoList = driver.findElements(By.className("list-unstyled ac-list"));
         System.out.println(autoList.size());
         
        
         if(autoList.size() == 0) {
             System.out.println("Results not found");

        }
        else {
             System.out.println("List found with elements " +autoList.size());
        }
        
        for(WebElement al : autoList)
        {
            if(al.getText().contains("Armin")) {
                 al.click();
                    break;
            }
            
        }
        }

    }

1 Answer

0

This is a little tricky one.

So first thing first,

below block will not work, so remove it.

try{
                (new WebDriverWait(driver, 6/*sec*/)).
                        until(ExpectedConditions.elementToBeClickable((By.className("clearfix "))));          
                        }
            catch(org.openqa.selenium.TimeoutException e){
                System.out.println(e.getMessage());
            }

because I can see that By.className("clearfix ") contains space and that will throw an exception for sure. That exception we are not throwing it back to the code and simply printing on console. So, that exception will never show up as an exception.

Second thing, as per my experience, clearfix is a very common class name. I am sure more than one element will be using that class name. So, again the code will fail either with an exception saying "class name can not have space" or your wait will simply pass because element if identified.

The right thing to do is, identify the autoList

List<WebElement> autoList = driver.findElements(By.className("list-unstyled ac-list"));


and wait until the size of this autoList is greater than 0.

Something like,

List<WebElement> autoList = driver.findElements(By.className("list-unstyled ac-list"));
do{
Thread.sleep(1000); //This thread.sleep will make thread wait for one second. It does not really harm and its good practice.
autoList = driver.findElements(By.className("list-unstyled ac-list"));
}while(autoList.size()>0);

Once it has some elements, then you can loop through using while,

for(WebElement al : autoList)
        {
            if(al.getText().contains("Armin")) {
                 al.click();
                    break;
            }
            
        } 
        } 


 

answered Sep 14 by SunilBhaskar (433 points)
4Comments
commented Sep 14 by Priyanka91 (91 points)
Thanks Sunil. I found where I was wrong. Yes, you are right! 'Clearfix' is very common and it had many sub-elements. Used some generic class name like 'item-name-inner' name to over the issue.
commented Sep 14 by stbadmin (4,970 points)
great! I am glad it worked!
commented Sep 14 by Priyanka91 (91 points)
Hi Sunil,

For the below code:

public class CommentTask {
    WebDriver driver;
   
    public CommentTask(WebDriver driver)
    {
        this.driver = driver;
    }
   

    public void commentOnTask()
    {
        WebDriverWait wait = new WebDriverWait(driver, 10);
        try {
             
         wait.until(ExpectedConditions.visibilityOfElementLocated(By.className("text_div")));
           
        }
        catch(org.openqa.selenium.TimeoutException e){
            System.out.println(e.getMessage());
               
        }
       
        driver.findElement(By.className("text_div")).sendKeys("Test Comment");
    WebElement submitButton =    wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*[@id=\"comments-task-6-59ba23e91bb06\"]/div/div/div[3]/div[2]/form/button")));
    submitButton.click();
   

    }

}

Am able to enter text into the Comment field but unable to find the path of Submit button and click on it. getting below exception:
WARNING: WebDriverException thrown by findElement(By.xpath: //*[@id="comments-task-6-59ba23e91bb06"]/div/div/div[3]/div[2]/form/button)
org.openqa.selenium.WebDriverException: Failed to decode response from marionette.

Can you please help me with this
commented Sep 14 by stbadmin (4,970 points)
This is a new issue. New issue should be posted as a new question. I will get it posted as a new question.
https://softwaretestingboard.com/qna/2401/warning-webdriverexception-thrown-by-findelement-by-xpath

Top Contributors

  • 4970 pointsstbadmin

    34 questions 454 answers218 comments

  • 433 pointsSunilBhaskar

    41 questions 15 answers32 comments

  • 425 pointsMehedi

    36 questions 3 answers14 comments

  • 363 pointssumitkumarwatts

    0 questions 13 answers0 comments

  • 354 pointsSoft Tester

    43 questions 0 answers4 comments

  • 327 pointsKeeshaGolden

    0 questions 17 answers2 comments

  • 322 pointsVipul Sharma

    44 questions 0 answers24 comments

  • 310 pointsvysh.sharma

    25 questions 0 answers0 comments

  • 267 pointsOnkar_Nimje

    33 questions 15 answers15 comments

  • 258 pointsVanitha

    26 questions 0 answers6 comments

...