Search
 
 

Display results as :
 


Rechercher Advanced Search

Latest topics
» FlexMonkium Download Not available under Gorillalogic site
Thu Dec 08, 2016 5:40 pm by bhanu.praveen

» Selenium Script issue
Tue Dec 06, 2016 9:48 pm by njain213

» Difference between QTP, Selenium and Silk test
Tue Dec 06, 2016 7:58 pm by jessicacyrus1

» Where does selenium script pick browser from
Tue Dec 06, 2016 1:52 pm by janbaskt

» Safari throws an HTTP ERROR: 404
Tue Dec 06, 2016 1:51 pm by janbaskt

» Access Denied Error in Selenium RC
Tue Dec 06, 2016 1:51 pm by janbaskt

» Automating Flex application through selenium webdriver
Fri Dec 02, 2016 2:06 pm by abhinay.krs

» Starting with Selenium, what is Selenium?
Mon Nov 28, 2016 4:00 pm by Foma

» Getting started with Selenium
Mon Nov 28, 2016 3:23 pm by Rebbelx

Navigation
 Portal
 Index
 Memberlist
 Profile
 FAQ
 Search

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

View previous topic View next topic Go down

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

Post by niloy.81 on 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..

niloy.81

Posts : 2
Join date : 2013-02-21

Back to top Go down

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

Post by vikas.gandhi on 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();

vikas.gandhi

Posts : 5
Join date : 2012-03-20

Back to top Go down

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

Post by niloy.81 on 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

niloy.81

Posts : 2
Join date : 2013-02-21

Back to top Go down

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

Post by Sponsored content Today at 1:49 pm


Sponsored content


Back to top Go down

View previous topic View next topic Back to top

- Similar topics

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