-
-
Notifications
You must be signed in to change notification settings - Fork 2.7k
Description
Have you read the Contributing Guidelines on issues?
- I have read the Contributing Guidelines on issues.
WebdriverIO Version
8.6.7
Node.js Version
18.14.2
Mode
Standalone Mode
Which capabilities are you using?
{
browserName: "chrome",
maxInstances: 1
}What happened?
For our project, we have preferred selecting an element by text. This helped us select very minor elements easily and quickly but recently we observed it was not able to select the required elements.
After deep dive we have observed, the following change
For instance, for the below snipped, in order to select the button
<button>
<span>Button Text</span>
</button>we wrote the following script,
$("button=Button Text").click()but now we are now required to write
$("span=Button Text").click()In the first case the main advantage was;
- Allow Users to select the Parent elements based on the text regardless of its child nodes
expect($("button#button-id")).toHaveText("Button Text")- From the User perspective, both tags have the same Text.
And after we updated our packages we faced this issue, after some exploring, I really accept the motive behind #9992 which is technically correct since span is the only element having that text but from the user perspective, it is also valid to say that the button tag has the same text.
What is your expected behavior?
Both methods must be allowed to select any element with the requested text.
$("button=Button Text").click()$("span=Button Text").click()How to reproduce the bug.
To reproduce this bug, please execute this following standalone code:
Aim: To select the Following Button for Sign In
Target Element's HTML
<a class="gb_ja gb_ka gb_ge gb_gd">
<span class="gb_ie">Sign in</span>
</a>Automation Script
import { remote } from 'webdriverio'
const browser = await remote({
capabilities: {
browserName: 'chrome',
'goog:chromeOptions': {
args: process.env.CI ? ['headless', 'disable-gpu'] : []
}
}
})
await browser.url('https://www.google.com/')
if(await browser.$("span=Sign in").getText("Sign in") !== "Sign in")
throw new Error("Failed")
try{
await browser.$("button=Sign in").getText();
}
catch(error){
console.log("Fails because of the error: ", error);
}
finally{
console.log("Please allow both the notations");
}
await browser.deleteSession();Relevant log output
023-03-23T18:53:48.391Z INFO devtools:puppeteer: Initiate new session using the DevTools protocol
2023-03-23T18:53:48.395Z INFO devtools: Launch Google Chrome (undefined) with flags: --enable-automation --disable-popup-blocking --disable-extensions --disable-background-networking --disable-background-timer-throttling --disable-backgrounding-occluded-windows --disable-sync --metrics-recording-only --disable-default-apps --mute-audio --no-first-run --no-default-browser-check --disable-hang-monitor --disable-prompt-on-repost --disable-client-side-phishing-detection --password-store=basic --use-mock-keychain --disable-component-extensions-with-background-pages --disable-breakpad --disable-dev-shm-usage --disable-ipc-flooding-protection --disable-renderer-backgrounding --force-fieldtrials=*BackgroundTracing/default/ --enable-features=NetworkService,NetworkServiceInProcess --disable-features=site-per-process,TranslateUI,BlinkGenPropertyTrees --window-position=0,0 --window-size=1200,900
2023-03-23T18:53:48.966Z INFO devtools: Connect Puppeteer with browser on port 58770
2023-03-23T18:53:49.375Z INFO devtools: COMMAND navigateTo("https://www.google.com/")
2023-03-23T18:53:51.043Z INFO devtools: RESULT null
2023-03-23T18:53:51.053Z INFO devtools: COMMAND findElement("xpath", ".//span[normalize-space(text()) = "Sign in"]")
2023-03-23T18:53:51.108Z INFO devtools: RESULT { 'element-6066-11e4-a52e-4f735466cecf': 'ELEMENT-1' }
2023-03-23T18:53:51.121Z INFO devtools: COMMAND getElementText("ELEMENT-1")
2023-03-23T18:53:51.131Z INFO devtools: RESULT Sign in
2023-03-23T18:53:51.134Z INFO devtools: COMMAND findElement("xpath", ".//button[normalize-space(text()) = "Sign in"]")
2023-03-23T18:53:51.145Z INFO devtools: RESULT Error: Element with selector ".//button[normalize-space(text()) = "Sign in"]" not found
at DevToolsDriver.findElement (file:///..//WebdriverioPlayground/node_modules/devtools/build/utils.js:98:16)
at process.processTicksAndRejections (node:internal/process/task_queues:95:5)
at async Browser.wrappedCommand (file:///..//WebdriverioPlayground/node_modules/devtools/build/devtoolsdriver.js:127:26)
at async Browser.wrapCommandFn (file:///..//WebdriverioPlayground/node_modules/@wdio/utils/build/shim.js:72:29)
at async Browser.$ (file:///..//WebdriverioPlayground/node_modules/webdriverio/build/commands/browser/$.js:74:17)
at async Browser.wrapCommandFn (file:///..//WebdriverioPlayground/node_modules/@wdio/utils/build/shim.js:72:29)
at async file:///..//WebdriverioPlayground/test.js:19:5
2023-03-23T18:53:51.155Z INFO devtools: COMMAND findElements("xpath", ".//button[normalize-space(text()) = "Sign in"]")
2023-03-23T18:53:51.165Z INFO devtools: RESULT []
2023-03-23T18:53:51.661Z INFO devtools: COMMAND findElements("xpath", ".//button[normalize-space(text()) = "Sign in"]")
2023-03-23T18:53:51.676Z INFO devtools: RESULT []
2023-03-23T18:53:52.169Z INFO devtools: COMMAND findElements("xpath", ".//button[normalize-space(text()) = "Sign in"]")
2023-03-23T18:53:52.181Z INFO devtools: RESULT []
2023-03-23T18:53:52.662Z INFO devtools: COMMAND findElements("xpath", ".//button[normalize-space(text()) = "Sign in"]")
2023-03-23T18:53:52.674Z INFO devtools: RESULT []
2023-03-23T18:53:53.159Z INFO devtools: COMMAND findElements("xpath", ".//button[normalize-space(text()) = "Sign in"]")
2023-03-23T18:53:53.168Z INFO devtools: RESULT []
2023-03-23T18:53:53.667Z INFO devtools: COMMAND findElements("xpath", ".//button[normalize-space(text()) = "Sign in"]")
2023-03-23T18:53:53.686Z INFO devtools: RESULT []
Fails because of the error: Error: Can't call getText on element with selector "button=Sign in" because element wasn't found
at implicitWait (file:///..//WebdriverioPlayground/node_modules/webdriverio/build/utils/implicitWait.js:29:19)
at async Element.elementErrorHandlerCallbackFn (file:///..//WebdriverioPlayground/node_modules/webdriverio/build/middlewares.js:14:29)
at async Element.wrapCommandFn (file:///..//WebdriverioPlayground/node_modules/@wdio/utils/build/shim.js:72:29)
at async file:///..//WebdriverioPlayground/test.js:19:5
Please allow both the notations
2023-03-23T18:53:54.165Z INFO devtools: COMMAND deleteSession()
2023-03-23T18:53:54.167Z INFO devtools: RESULT nullCode of Conduct
- I agree to follow this project's Code of Conduct
Is there an existing issue for this?
- I have searched the existing issues
