0

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>
7
  • above code I tried Commented Jan 2, 2019 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
    Commented Jan 2, 2019 at 20:27
  • reason is i cannot understand how to get the above image ebay link Commented Jan 2, 2019 at 20:30
  • 1
    so find a unique identifying attribute for the link, use the dev console?
    – Doug Clark
    Commented Jan 2, 2019 at 20:34
  • update my question Commented Jan 2, 2019 at 20:58

1 Answer 1

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 and acknowledge you have read our privacy policy.

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