-1

enter image description here

I want to test the Ebay site login, without using Xpath. It is not working, right now. I tried for hours to make this work. Please tell me what I am doing wrong and how to fix it.

This is what I am doing:

  1. Open Google website
  2. Search for “ebay” website
  3. Click on the appropriate result
  4. Go to http://www.ebay.com website
  5. Click on the “Sign in” link to navigate to the ebay login page
  6. Enter email address/password
  7. Click on Sign In button
  8. Verify your user name.

package Script;

import org.openqa.selenium.By;
import org.openqa.selenium.WebDriver;
import org.openqa.selenium.firefox.FirefoxDriver;
import org.testng.annotations.Test;

public class TestEbay_login {
    @Test
    public void ebay_login() throws InterruptedException {

            System.setProperty("webdriver.gecko.driver", "C:\\Users\\Senani\\Downloads\\Programs\\geckodriver-v0.23.0-win64\\geckodriver.exe");
            WebDriver driver = new  FirefoxDriver();
            //driver.get("https://www.google.com");
            driver.navigate().to("https://www.google.com");
            driver.manage().window().maximize();
            driver.findElement(By.name("q")).sendKeys("ebay");
            driver.findElement(By.name("btnK")).submit();
            driver.findElement(By.cssSelector("a[href='www.ebay.com']")).click();
            driver.findElement(By.linkText("Sign in")).click();
            driver.findElement(By.id("userid")).sendKeys("*******");
            driver.findElement(By.id("pass")).sendKeys("*******");

            driver.findElement(By.id("sgnBt")).click();
    }
}

FAILED: ebay_login org.openqa.selenium.NoSuchElementException: Unable to locate element: a[href='www.ebay.com'] For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/no_such_element.html Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:25:48'

update question how to find unique anything this element. Can anyone help me. I'm stuck in this code.

<a href="https://www.ebay.com/" ping="/url?sa=t&amp;source=web&amp;rct=j&amp;url=https://www.ebay.com/&amp;ved=2ahUKEwjDpP21_c_fAhWLLY8KHXYwB9gQFjAAegQIAxAC">
    <h3 class="LC20lb">eBay: Electronics, Cars, Fashion, Collectibles, Coupons and More</h3>
    <br>
    <div style="display:inline-block" class="TbwUpd">
        <cite class="iUh30">https://www.ebay.com/</cite>
    </div>
</a>
  • above code I tried – Poorna Senani Gamage Jan 2 at 19:55
  • 1
    so nothing. the error states Unable to locate element: a[href='www.ebay.com'], so that element must not be on the page – Doug Clark Jan 2 at 20:27
  • reason is i cannot understand how to get the above image ebay link – Poorna Senani Gamage Jan 2 at 20:30
  • 1
    so find a unique identifying attribute for the link, use the dev console? – Doug Clark Jan 2 at 20:34
  • update my question – Poorna Senani Gamage Jan 2 at 20:58
4

It looks live you've answered your own question

driver.findElement(By.cssSelector("a[href='www.ebay.com']"))

but the DOM says that element is

<a href="https://www.ebay.com/" ..../>

So update your code to reflect this different href exactly

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.