Selenium Forum: Functional And Regression Testing Tool.
Would you like to react to this message? Create an account in a few clicks or log in to continue.
Search
Display results as :
Advanced Search
Latest topics
AEM Training | Free Online DemoWed Apr 21, 2021 5:45 pmazharuddin
c# PageFactory - issue initializing elementsFri Nov 01, 2019 8:40 pmthegoatboy
Selenium making automatic connection to random urlsMon Jul 08, 2019 12:58 pmrepairtechsolutions1
How can we design the custom framework in Selenium RCMon Jun 24, 2019 2:26 pmrandybonnettes
What are the new features in Selenium 3.0Tue Jun 18, 2019 5:37 pmpappyvicky
What are you using Selenium for? Fri Apr 12, 2019 3:52 amzhl
LIMITATIONS OF SELENIUMWed Apr 10, 2019 11:23 amswara
Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

Go down
avatar
niloy.81
Posts : 2
Join date : 2013-02-21

Not able to locate the element error on trying to click a link in menu Empty Not able to locate the element error on trying to click a link in menu

Thu Feb 21, 2013 4:58 pm
Can anyone help me on this? I need to click on the link loacted in menu..i use driver.findElement(By.linkText("Matches & Results")).click(); but its shows not able to locate..
avatar
vikas.gandhi
Posts : 5
Join date : 2012-03-20

Not able to locate the element error on trying to click a link in menu Empty Re: Not able to locate the element error on trying to click a link in menu

Mon Mar 04, 2013 6:42 pm
You can try this -
driver.get("Your Site");
WebElement ele = driver.findElement(By.xpath("Main Menu say - File"));
WebElement ele1 = driver.findElement(By.xpath("Sub Menu say - Matches & Results"));
Actions builder = new Actions(driver);
driver.manage().timeouts().implicitlyWait(5, TimeUnit.SECONDS);
builder.moveToElement(ele).build().perform();
Actions builder1 = new Actions(driver);
builder1.moveToElement(ele1).build().perform();
ele1.click();
avatar
niloy.81
Posts : 2
Join date : 2013-02-21

Not able to locate the element error on trying to click a link in menu Empty Re: Not able to locate the element error on trying to click a link in menu

Tue Mar 05, 2013 4:13 pm
Thanks Vikas for your help...my code looks like this now:

import java.util.List;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.concurrent.TimeUnit;
import org.apache.bcel.generic.Select;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.openqa.selenium.By;
import org.openqa.selenium.By.ById;
import org.openqa.selenium.JavascriptExecutor;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.WebElement;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.openqa.selenium.interactions.Actions;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
import org.testng.annotations.AfterTest;
import org.testng.annotations.BeforeMethod;
import org.testng.annotations.BeforeTest;


import com.beust.jcommander.Parameters;
import com.thoughtworks.selenium.Wait;

public class SecondTestCase {

@BeforeTest
public void setUp() throws Exception {
WebDriver driver = new FirefoxDriver();
driver.get("http://espnfc.com/us/en");

}

@Test
public void MDDcheck() throws Exception {

WebDriver driver = new FirefoxDriver();
driver.get("http://espnfc.com/us/en");
driver.manage().window().maximize();
WebElement myElement1=driver.findElement(By.xpath("//a[text()='Matches & Results']"));
Actions builder = new Actions(driver);
builder.moveToElement(myElement1).build().perform();
Thread.sleep(5000);
WebElement myElement2=driver.findElement(By.xpath("//a[text()='Groups & Teams']"));
Actions builder1 = new Actions(driver);
builder1.moveToElement(myElement2).build().perform();
Thread.sleep(5000);
WebElement myElement3=driver.findElement(By.xpath("html/body/header/div/nav/div/section[4]/h1/a"));
Actions builder2 = new Actions(driver);
builder2.moveToElement(myElement3).build().perform();
Thread.sleep(5000);
driver.findElement(By.linkText("Full Table")).click();
WebElement myElement4=driver.findElement(By.xpath("//a[text()='News & Features']"));
Actions builder3 = new Actions(driver);
builder3.moveToElement(myElement4).build().perform();
Thread.sleep(5000);
WebElement myElement5=driver.findElement(By.xpath("//a[text()='About Euros']"));
Actions builder4 = new Actions(driver);
builder4.moveToElement(myElement5).build().perform();
Thread.sleep(5000);
WebElement myElement6=driver.findElement(By.xpath("//html/body/header/div/nav/div/section[7]/h1/a"));
Actions builder5 = new Actions(driver);
builder5.moveToElement(myElement6).build().perform();
Thread.sleep(5000);

}

@Test
public void pageCheck() {

WebDriver driver = new FirefoxDriver();
driver.get("http://espnfc.com/us/en");
driver.manage().window().maximize();

driver.findElement(By.xpath("html/body/header/div/nav/div/section[3]/h1/a")).click();
/*
driver.findElement(By.xpath("//*[@id='dropdown-menu']/li[2]/a]")).click();
driver.findElement(By.xpath("//a[contains(text(),'Group B')]")).click();
driver.findElement(By.xpath("//a[contains(text(),'Group C')]")).click();
driver.findElement(By.xpath("//a[contains(text(),'Group D')]")).click();
*/
driver.findElement(By.xpath("html/body/header/div/nav/div/section[4]/h1/a")).click();
driver.findElement(By.xpath("(//a[contains(text(),'Fernando Torres')])[2]")).click();
driver.navigate().back();
driver.findElement(By.xpath("//*[@id='site-nav-main']/div/section[5]/h1/a")).click();
driver.findElement(By.xpath("//*[@id='dropdown-menu']/li[2]/a")).click();
driver.findElement(By.xpath("//*[@id='photos-block']/ul/li[1]/a/span/figure/img")).click();
driver.findElement(By.xpath("//*[@id='overlay-close']")).click();
driver.findElement(By.xpath("//*[@id='dropdown-menu']/li[3]/a")).click();
driver.findElement(By.xpath("//*[@id='videos-block-01']/ul/li[1]/a/span/figure/div/div]"));
driver.manage().timeouts().pageLoadTimeout(100,TimeUnit.SECONDS);
driver.findElement(By.xpath("//*[@id='site-nav-main']/div/section[6]/h1/a")).click();
driver.findElement(By.xpath("//*[@id='main-content']/div[1]/section[2]/ul/li[1]/div/h2/a")).click();

}

@AfterTest

public void Teardown(){
driver.close("Close the browser");
}




}


But when i run this script in TestNg it shows results like below:

[TestNG] Running:
C:\Users\chakrabn\AppData\Local\Temp\testng-eclipse--268752105\testng-customsuite.xml


===============================================
Default test
Tests run: 0, Failures: 0, Skips: 0
===============================================


===============================================
Default suite
Total tests run: 0, Failures: 0, Skips: 0
===============================================

[TestNG] Time taken by org.testng.reporters.EmailableReporter2@509df6f1: 27 ms
[TestNG] Time taken by org.testng.reporters.SuiteHTMLReporter@79a5f739: 352 ms
[TestNG] Time taken by org.testng.reporters.XMLReporter@939b78e: 41 ms
[TestNG] Time taken by org.testng.reporters.jq.Main@1572e449: 181 ms
[TestNG] Time taken by [FailedReporter passed=0 failed=0 skipped=0]: 1 ms
[TestNG] Time taken by org.testng.reporters.JUnitReportReporter@78dc6a77: 0 ms

Please suggest if annotations are correct
Sponsored content

Not able to locate the element error on trying to click a link in menu Empty Re: Not able to locate the element error on trying to click a link in menu

Back to top
Permissions in this forum:
You cannot reply to topics in this forum