0

I'm trying to click an element on payment pop-up:

<label data-v-533987c6="" xpath="1">Card Number:</label>
<input data-v-533987c6="" type="tel" data-mask="#### #### #### ####" data-previous-value="" xpath="1">

with following xPath:

@FindBy(name = "//div[contains(@class,'buy-tickets')]//div/label[text()='Card Number:']/following-sibling::input")

but I receive this error:

org.openqa.selenium.InvalidSelectorException: invalid selector: An invalid or illegal selector was specified
  (Session info: chrome=80.0.3987.87)
For documentation on this error, please visit: https://www.seleniumhq.org/exceptions/invalid_selector_exception.html
Build info: version: '3.141.59', revision: 'e82be7d358', time: '2018-11-14T08:17:03'
System info: host: 'DESKTOP-VQ56FMV', ip: '192.168.0.13', os.name: 'Windows 10', os.arch: 'amd64', os.version: '10.0', java.version: '1.8.0_231'
Driver info: org.openqa.selenium.remote.RemoteWebDriver
Capabilities {acceptInsecureCerts: false, browserName: chrome, browserVersion: 80.0.3987.87, chrome: {chromedriverVersion: 80.0.3987.106 (f68069574609..., userDataDir: C:\Users\Nastya\AppData\Loc...}, goog:chromeOptions: {debuggerAddress: localhost:64958}, javascriptEnabled: true, networkConnectionEnabled: false, pageLoadStrategy: normal, platform: WINDOWS, platformName: WINDOWS, proxy: Proxy(), setWindowRect: true, strictFileInteractability: false, timeouts: {implicit: 0, pageLoad: 300000, script: 30000}, unhandledPromptBehavior: dismiss and notify, webdriver.remote.sessionid: 3ca3f388f2b3cf47642733a6f03...}
Session ID: 3ca3f388f2b3cf47642733a6f0383c1e
*** Element info: {Using=name, value=//div[contains(@class,'buy-tickets')]//div/label[text()='Card Number:']/following-sibling::input}

Why? Hope, you can help me!

  • The selector that is causing the issue is not the one you posted, but the one the message reports on the last line ( //div[contains(@class,'buy-tickets')]//div/label[text()='Card Number:']/following-sibling::input} ) Can you confirm that you are in fact using code that extracts using XPath, and not using CSS Selectors? – havanagrawal Feb 16 '20 at 21:02

4 Answers4

0

You seem to be close. Though you have mentioned the Locator Strategy as By.name in your code, but the value which you have passed:

//label[text()='Expiration Date:']//following::input[@type='tel'][1]

resembles a . So instead of using By.name you need to use By.xpath and you can use either of the following solutions:

  • xpath 1 using following:

    driver.findElement(By.xpath("//label[text()='Card Number:']//following::input[1]"))
    
  • xpath 2 using following-sibling:

    driver.findElement(By.xpath("//label[text()='Card Number:']//following-sibling::input[1]"))
    
undetected Selenium
  • 183,867
  • 41
  • 278
  • 352
0

According to the error message

Element info: {Using=name, value=//div[contains(@class,'buy-tickets')]//div/label[text()='Card Number:']/following-sibling::input}

you are trying to use another xpath

//div[contains(@class,'buy-tickets')]//div/label[text()='Card Number:']/following-sibling::input`

with By.name, which is invalid. You need to use By.xpath.

Guy
  • 46,488
  • 10
  • 44
  • 88
0

Error message is explaining itself

*** Element info: {Using=name, value=//div[contains(@class,'buy-tickets')]//div/label[text()='Card Number:']/following-sibling::input}

You are using xpath but selector is using name

driver.findElement(By.xpath("//label[contains(text(),'Card Number')]/following-sibling::input"));
Muzzamil
  • 2,823
  • 2
  • 11
  • 23
0

Because this selector is XPath You can find an element By css, xpath, name etc Just replace

@FindBy(name = "//div[contains(@class,'buy-tickets')]//div/label[text()='Card Number:']/following-sibling::input"

with

@FindBy(xpath = "//div[contains(@class,'buy-tickets')]//div/label[text()='Card Number:']/following-sibling::input"