0
<a class="top-menu-item float-start  p-2" href="/StudentPortal/Home/Login"> تسجيل دخول </a>

Im not able to locate the element mentioned above for automation purpose

I have tried the below xpath:

driver.findElement(By.xpath("/html/body/header/div[1]/div/a[3]"));

and

driver.findElement(By.xpath("/html/body/header/div[1]/div/a[3]"));
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352

3 Answers3

0

You can try the following xpath -

driver.findElement(By.xpath("//a[contains(@href,'/StudentPortal/Home/Login')"))

demouser123
  • 4,108
  • 9
  • 50
  • 82
0

To locate the element you can use either of the Locator Strategies:

  • partialLinkText:

    WebElement element = driver.findElement(By.partialLinkText("تسجيل دخول"));
    
  • cssSelector:

    WebElement element = driver.findElement(By.cssSelector("a.top-menu-item.float-start.p-2[href='/StudentPortal/Home/Login']"));
    
  • xpath:

    WebElement element = driver.findElement(By.xpath("//a[@class='top-menu-item float-start  p-2' and @href='/StudentPortal/Home/Login']"));
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
  • Your first locator won't work because you are missing the padding spaces on either side of the text. The rest are just messy because you are including EVERYTHING in the element as a locator which just makes them more likely to be brittle. – JeffC Apr 01 '19 at 20:13
0

You can use below locators:

Xpath CSS ID