Skip to content

Commit

Permalink
Revert "Adds ability to identify element using resource-id for appium (
Browse files Browse the repository at this point in the history
…#7574)" due to comment made by @nextlevelbeard (#7574 (comment))

This reverts commit 1ae75b9.
  • Loading branch information
christian-bromann committed Oct 20, 2021
1 parent 1ae75b9 commit a9ef72b
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 26 deletions.
9 changes: 4 additions & 5 deletions packages/webdriverio/src/utils/findStrategy.ts
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ const IMAGEPATH_MOBILE_SELECTORS_ENDSWITH = [

type SelectorStrategy = string | { name: string, args: string }

const defineStrategy = function (selector: SelectorStrategy, isMobile?: boolean) {
const defineStrategy = function (selector: SelectorStrategy) {
// Condition with checking isPlainObject(selector) should be first because
// in case of "selector" argument is a plain object then .match() will cause
// an error like "selector.match is not a function"
Expand Down Expand Up @@ -64,7 +64,7 @@ const defineStrategy = function (selector: SelectorStrategy, isMobile?: boolean)
return 'partial link text'
}
// Use id strategy if the selector starts with id=
if (stringSelector.startsWith('id=') || (isMobile && stringSelector.startsWith('#'))) {
if (stringSelector.startsWith('id=')) {
return 'id'
}
// use shadow dom selector
Expand Down Expand Up @@ -118,7 +118,7 @@ export const findStrategy = function (selector: SelectorStrategy, isW3C?: boolea
let using: string = DEFAULT_STRATEGY
let value = selector as string

switch (defineStrategy(selector, isMobile)) {
switch (defineStrategy(selector)) {
// user has specified locator strategy directly
case 'directly': {
const match = stringSelector.match(DIRECT_SELECTOR_REGEXP)
Expand All @@ -135,8 +135,7 @@ export const findStrategy = function (selector: SelectorStrategy, isW3C?: boolea
}
case 'id': {
using = 'id'
value = stringSelector.startsWith('#') ?
stringSelector.slice(1) : stringSelector.slice(3)
value = stringSelector.slice(3)
break
}
case 'link text': {
Expand Down
6 changes: 0 additions & 6 deletions packages/webdriverio/tests/findStrategy.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -446,10 +446,4 @@ describe('selector strategies helper', () => {
expect(element.using).toBe('shadow')
expect(element.value).toBe('.foobar')
})

it('should find an element using "id" method for mobile device', () => {
const element = findStrategy('#purplebox', undefined, true)
expect(element.using).toBe('id')
expect(element.value).toBe('purplebox')
})
})
17 changes: 2 additions & 15 deletions website/docs/Selectors.md
Original file line number Diff line number Diff line change
Expand Up @@ -183,25 +183,12 @@ const button = await $('[role=button]')
console.log(await button.click())
```

## ID Attribute
## id

Locator strategy "id" is not supported in WebDriver protocol, one should use either CSS or xPath selector strategies instead to find elements using ID.
Finding element by id has no specific syntax in WebDriver and one should use either CSS selectors (`#<my element ID>`) or xPath (`//*[@id="<my element ID>"]`).

However some drivers (e.g. [Appium You.i Engine Driver](https://github.com/YOU-i-Labs/appium-youiengine-driver#selector-strategies)) might still [support](https://github.com/YOU-i-Labs/appium-youiengine-driver#selector-strategies) this selector.

Current supported selector syntaxes for ID are:

```js
//css locator
const button = await $('#someid')
//xpath locator
const button = await $('//*[@id="someid"'])
//id strategy
// Note: works only in Appium or similar frameworks which supports locator strategy "ID"
const button = await $('id=resource-id')
const button = await $('#resource-id')
```

## JS Function

You can also use JavaScript functions to fetch elements using web native APIs. Of course, you can only do this inside a web context (e.g., `browser`, or web context in mobile).
Expand Down

0 comments on commit a9ef72b

Please sign in to comment.