I am teaching myself automation with web driver, and thought a good way was to learn off an ecommerce site such as . I am trying to locate inner with and used the following to verify logged in user name via page factory:

    @FindBy (how=How.CSS, using= "a:contains('Hello,Nichole')") WebElement loggedInUsernameText;

Error Message: org.openqa.selenium.InvalidSelectorException: invalid selector: An invalid or illegal selector was specified

Unfortunately this did not work for me, so I tried to use :

@FindBy (how=How.XPATH, using= "//*[contains(text(),('Hello,Nichole')]") WebElement loggedInUsernameText;

Error Message: org.openqa.selenium.InvalidSelectorException: invalid selector: Unable to locate an element with the xpath expression //[contains(text(),(‘Hello,Nichole’)] because of the following error:
SyntaxError: Failed to execute ‘evaluate’ on ‘Document’: The string ‘//
[contains(text(),(‘Hello,Nichole’)]’ is not a valid XPath expression.

This didn’t work for me either- can someone please tell me what I am doing wrong?

Here is the locator for CSS and Xpath:

    <span class="nav-line-1">Hello, Nichole</span>

CSS:
#nav-link-accountList > span.nav-line-1

XPath:
//*[@id=”nav-link-accountList”]/span[1]

I am probably doing something really dumb! Let me know if I need to provide other information- oh to find it on the console it does specify to use $0- which I did use and it located it, so I am guessing I need to implement that somehow?



Source link https://sqa.stackexchange.com/questions/34983/-inner-text-with-css-or-xpath-amazon

LEAVE A REPLY

Please enter your comment!
Please enter your name here