Checkout our demo site to practice selenium https://magento.softwaretestingboard.com/

0 like 0 dislike
939 views
in Selenium by

I am getting following error while running my program:

The error:

Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"link text","selector":"Link Test"}
Command duration or timeout: 78 milliseconds
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 02:56:46'
System info: host: 'LT03691', ip: '192.168.254.1', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_60'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{applicationCacheEnabled=true, rotatable=false, handlesAlerts=true, databaseEnabled=true, version=40.0.3, platform=WINDOWS, nativeEvents=false, acceptSslCerts=true, webStorageEnabled=true, locationContextEnabled=true, browserName=firefox, takesScreenshot=true, javascriptEnabled=true, cssSelectorsEnabled=true}]
Session ID: 275b1ae1-0276-48b8-8c22-a1fec2fa8cfe
*** Element info: {Using=link text, value=Link Test}
    at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
    at sun.reflect.NativeConstructorAccessorImpl.newInstance(Unknown Source)
    at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(Unknown Source)
    at java.lang.reflect.Constructor.newInstance(Unknown Source)
    at org.openqa.selenium.remote.ErrorHandler.createThrowable(ErrorHandler.java:206)
    at org.openqa.selenium.remote.ErrorHandler.throwIfResponseFailed(ErrorHandler.java:158)
    at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:595)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:348)
    at org.openqa.selenium.remote.RemoteWebDriver.findElementByLinkText(RemoteWebDriver.java:397)
    at org.openqa.selenium.By$ByLinkText.findElement(By.java:243)
    at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:340)
    at newpackage.Forms.main(Forms.java:18)
Caused by: org.openqa.selenium.NoSuchElementException: Unable to locate element: {"method":"link text","selector":"Link Test"}
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: '2.47.1', revision: '411b314', time: '2015-07-30 02:56:46'
System info: host: 'LT03691', ip: '192.168.254.1', os.name: 'Windows 7', os.arch: 'x86', os.version: '6.1', java.version: '1.8.0_60'
Driver info: driver.version: unknown
    at <anonymous class>.FirefoxDriver.prototype.findElementInternal_(file:///C:/Users/ADM_SJ~1/AppData/Local/Temp/anonymous3541662467874884370webdriver-profile/extensions/[email protected]/components/driver-component.js:10667)
    at <anonymous class>.FirefoxDriver.prototype.findElement(file:///C:/Users/ADM_SJ~1/AppData/Local/Temp/anonymous3541662467874884370webdriver-profile/extensions/[email protected]/components/driver-component.js:10676)
    at <anonymous class>.DelayedCommand.prototype.executeInternal_/h(file:///C:/Users/ADM_SJ~1/AppData/Local/Temp/anonymous3541662467874884370webdriver-profile/extensions/[email protected]/components/command-processor.js:12643)
    at <anonymous class>.DelayedCommand.prototype.executeInternal_(file:///C:/Users/ADM_SJ~1/AppData/Local/Temp/anonymous3541662467874884370webdriver-profile/extensions/[email protected]/components/command-processor.js:12648)
    at <anonymous class>.DelayedCommand.prototype.execute/<(file:///C:/Users/ADM_SJ~1/AppData/Local/Temp/anonymous3541662467874884370webdriver-profile/extensions/[email protected]/components/command-processor.js:12590)
 

1 Answer

0 like 0 dislike
by
selected by
 
Best answer

Assumption:

It looks like your page has AJAX and element you are trying to look for is not yet clickable/visible as AJAX call is not yet completed.

Use below code to make webdriver wait until element is clickable.

WebDriverWait wait = new WebDriverWait(driver, 10); WebElement element = wait.until(ExpectedConditions.elementToBeClickable(By.id("someid")));

 

Can you post your code and HTML? to provide clear answer?

by
Thank you Mayur. The code is:

package newpackage;

import java.util.List;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;

public class Forms {

    public static void main(String[] args) {
        // TODO Auto-generated method stub
        WebDriver driver = new FirefoxDriver();
        String baseURL = "http://www.toolsqa.com/automation-practice-form/";
        W
       
        driver.get(baseURL);
        driver.findElement(By.linkText("Link Test")).click();
        driver.navigate().back();
        driver.findElement(By.partialLinkText("Partial Link Test")).click();
        //driver.navigate().back();
        driver.findElement(By.name("First name")).sendKeys("Soham");
        driver.findElement(By.name("Last name")).sendKeys("Jana");
       
        //Select the deselected Radio button (female) for category Sex (Use IsSelected method)
        // Storing all the elements under category 'Sex' in the list of WebLements
        List<WebElement> rdBtn_Sex = driver.findElements(By.name("sex"));
       
        // Create a boolean variable which will hold the value (True/False)
                boolean bValue = false;
               
        // This statement will return True, in case of first Radio button is selected
                bValue = rdBtn_Sex.get(0).isSelected();
               
                // This statement will return True, in case of first Radio button is selected
                bValue = rdBtn_Sex.get(0).isSelected();
               
                // This will check that if the bValue is True means if the first radio button is selected
                if(bValue == true){
                    // This will select Second radio button, if the first radio button is selected by default
                    rdBtn_Sex.get(1).click();
                }else{
                    // If the first radio button is not selected by default, the first will be selected
                    rdBtn_Sex.get(0).click();
                }
               
        //Step 4: Select the Third radio button for category 'Years of Exp' (Use Id attribute to select Radio button)
                WebElement rdBtn_Exp = driver.findElement(By.id("exp-2"));
                rdBtn_Exp.click();
               
        // STep 5: Check the Check Box 'Automation Tester' for category 'Profession'( Use Value attribute to match the selection)
        // Find the Check Box or radio button element by Name
                List<WebElement> chkBx_Profession = driver.findElements(By.name("profession"));
               
        // This will tell you the number of Check Boxes are present
                int iSize = chkBx_Profession.size();
               
        // Start the loop from first Check Box to last Check Boxe
                for(int i=0; i < iSize ; i++ ){
       
        // Store the Check Box name to the string variable, using 'Value' attribute
                    String sValue = chkBx_Profession.get(i).getAttribute("value");
                   
        // Select the Check Box it the value of the Check Box is same what you are looking for
                    if (sValue.equalsIgnoreCase("Automation Tester")){
                        chkBx_Profession.get(i).click();
        // This will take the execution out of for loop
                    break;
                    }
                }
               
       

    }


}
by
When I am looking at URL, server is down. Contact me on mayur [at] kagrana [dot] com. we will resolve this.
by
The url is working now. Please can you help me. I have sent you an email..


This site is for software testing professionals, where you can ask all your questions and get answers from 1300+ masters of the profession. Click here to submit yours now!

1.4k questions

1.6k answers

866 comments

1.9k users

...