fix: relative XPath chaining in BiDi mode#14912
fix: relative XPath chaining in BiDi mode#14912christian-bromann merged 2 commits intowebdriverio:mainfrom
Conversation
create-wdio
eslint-plugin-wdio
@wdio/allure-reporter
@wdio/appium-service
@wdio/browser-runner
@wdio/browserstack-service
@wdio/cli
@wdio/concise-reporter
@wdio/config
@wdio/cucumber-framework
@wdio/dot-reporter
@wdio/firefox-profile-service
@wdio/globals
@wdio/jasmine-framework
@wdio/json-reporter
@wdio/junit-reporter
@wdio/lighthouse-service
@wdio/local-runner
@wdio/logger
@wdio/mocha-framework
@wdio/protocols
@wdio/repl
@wdio/reporter
@wdio/runner
@wdio/sauce-service
@wdio/shared-store-service
@wdio/smoke-test-cjs-service
@wdio/smoke-test-reporter
@wdio/smoke-test-service
@wdio/spec-reporter
@wdio/static-server-service
@wdio/sumologic-reporter
@wdio/testingbot-service
@wdio/types
@wdio/utils
@wdio/webdriver-mock-service
@wdio/xvfb
webdriver
webdriverio
commit: |
| * we need to fall back to the regular WebDriver Classic command as BiDi | ||
| * does not support relative xpath selectors with a start node | ||
| */ | ||
| if (using === 'xpath' && (value.startsWith('./') || value.startsWith('..')) && (this as WebdriverIO.Element).elementId) { |
There was a problem hiding this comment.
As mentioned in the other PR, can we use startNodes to enable this?
There was a problem hiding this comment.
startNodes searches within descendants only. Sibling axes like ./following-sibling::* look outside, so Classic fallback is still needed. (This is my understanding - happy to be corrected if I'm wrong!)
|
Hey mccmrunal 👋 Thank you for your contribution to WebdriverIO! Your pull request has been marked as an "Expensable" contribution. We've sent you an email with further instructions on how to claim your expenses from our development fund. We are looking forward to more contributions from you in the future 🙌 Have a nice day, |
Fixes #14675
Proposed changes
This PR fixes an issue where chaining relative XPath selectors (e.g.,
element.$('./following-sibling::div')) fails when running in WebDriver BiDi mode (the default in v9).Root Cause:
The WebDriver BiDi
browsingContext.locateNodescommand, when provided withstartNodes, searches for elements within the descendants of those nodes. It does not interpret relative XPath expressions (starting with./or..) as relative to thestartNodesthemselves in the same way WebDriver Classic does. This caused selectors like./following-sibling::divto fail to find elements that are siblings of the context element.The Fix:
I updated
findDeepElementandfindDeepElementsin [packages/webdriverio/src/utils/index.ts] to detect this specific scenario:xpath../or..(indicating a relative path).elementIdis present).When these conditions are met, the code now falls back to using the WebDriver Classic
findElementFromElement(orfindElementsFromElement) command, ensuring the relative XPath is evaluated correctly against the context element.Types of changes
Checklist
Backport Request
//: # (The current
mainbranch is the development branch for WebdriverIO v9. If your change should be released to the current major version of WebdriverIO (v8), please raise another PR with the same changes against thev8branch.)v9and doesn't need to be back-ported#XXXXXFurther comments
I verified this fix by:
element.$('./following-sibling::div')which failed in BiDi mode.Reviewers: @webdriverio/project-committers