I am trying to run the below code but getting error. Can you please point out the issue
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;
import org.openqa.selenium.remote.DesiredCapabilities;
import org.openqa.selenium.support.ui.ExpectedConditions;
import org.openqa.selenium.support.ui.WebDriverWait;
public class Menu {
public static void main(String[] args) throws InterruptedException {
DesiredCapabilities capabilities = DesiredCapabilities.firefox();
capabilities.setCapability("acceptInsecureCerts", true);
capabilities.setJavascriptEnabled(true);
capabilities.setCapability("marionette", true);
System.setProperty("webdriver.gecko.driver","C:/Users/ikram/Downloads/geckodriver-v0.18.0-win64/geckodriver.exe");
WebDriver driver =new FirefoxDriver();
driver.get("http://awqaf.texpo.com/");
driver.switchTo().defaultContent();
//driver.switchTo().frame(0); // use this if it's in frame and you don't know how to locate it
//WebElement aboutdrop = (new WebDriverWait(driver, 15)).until(ExpectedConditions.presenceOfElementLocated(By.xpath("//a[contains(text(),'ABOUT US')]")));
WebElement aboutdrop=driver.findElement(By.xpath("//a[contains(text(),'ABOUT US')]"));
List<WebElement> about=aboutdrop.findElements(By.tagName("option"));
for (int i=0;i<=about.size();i++){
String value = about.get(i).getText();
System.out.println(value);
}
}
}
Error description
1500455460357 geckodriver INFO geckodriver 0.18.0
1500455460362 geckodriver INFO Listening on 127.0.0.1:11115
1500455461028 geckodriver::marionette INFO Starting browser C:\Program Files\Mozilla Firefox\firefox.exe with args ["-marionette"]
1500455466131 Marionette INFO Listening on port 53870
Jul 19, 2017 2:11:06 PM org.openqa.selenium.remote.ProtocolHandshake createSession
INFO: Detected dialect: W3C
Exception in thread "main" org.openqa.selenium.NoSuchElementException: Unable to locate element: //a[contains(text(),'ABOUT US')]
For documentation on this error, please visit: http://seleniumhq.org/exceptions/no_such_element.html
Build info: version: 'unknown', revision: 'unknown', time: 'unknown'
System info: host: 'SAIF', ip: '10.20.1.95', os.name: 'Windows 7', os.arch: 'amd64', os.version: '6.1', java.version: '1.8.0_131'
Driver info: org.openqa.selenium.firefox.FirefoxDriver
Capabilities [{moz:profile=C:\Users\ikram\AppData\Local\Temp\rust_mozprofile.daCtPib7HZe9, rotatable=false, timeouts={implicit=0.0, pageLoad=300000.0, script=30000.0}, pageLoadStrategy=normal, platform=ANY, specificationLevel=0.0, moz:accessibilityChecks=false, acceptInsecureCerts=false, browserVersion=54.0.1, platformVersion=6.1, moz:processID=7136.0, browserName=firefox, javascriptEnabled=true, platformName=windows_nt}]
Session ID: ef7987ee-c265-4f09-a38a-67c357c8d97e
*** Element info: {Using=xpath, value=//a[contains(text(),'ABOUT US')]}
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.http.W3CHttpResponseCodec.createException(W3CHttpResponseCodec.java:150)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:115)
at org.openqa.selenium.remote.http.W3CHttpResponseCodec.decode(W3CHttpResponseCodec.java:45)
at org.openqa.selenium.remote.HttpCommandExecutor.execute(HttpCommandExecutor.java:164)
at org.openqa.selenium.remote.service.DriverCommandExecutor.execute(DriverCommandExecutor.java:82)
at org.openqa.selenium.remote.RemoteWebDriver.execute(RemoteWebDriver.java:637)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:410)
at org.openqa.selenium.remote.RemoteWebDriver.findElementByXPath(RemoteWebDriver.java:509)
at org.openqa.selenium.By$ByXPath.findElement(By.java:361)
at org.openqa.selenium.remote.RemoteWebDriver.findElement(RemoteWebDriver.java:402)
at Menu.main(Menu.java:25)
WebElement aboutdrop=driver.findElement(By.xpath("//a[contains(text(),'ABOUT US')]"));
is not correct. Please provide relevant HTML so that a proper solution can be given.