Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get Value From Attribute #4

Closed
ebebbington opened this issue Sep 28, 2020 · 5 comments · Fixed by #123
Closed

Get Value From Attribute #4

ebebbington opened this issue Sep 28, 2020 · 5 comments · Fixed by #123
Assignees

Comments

@ebebbington
Copy link
Member

Summary

What: Add a public method to HeadlessBrowser to get the value for a given elements attribute

@crookse crookse changed the title Get Value From Attribute feat: Get Value From Attribute Oct 31, 2020
@crookse crookse changed the title feat: Get Value From Attribute Get Value From Attribute Nov 1, 2020
@ebebbington
Copy link
Member Author

Now we have evaluatePage, I feel it makes adding this feature pointless?

For example we can now do:

// html: <input id="username" user-id="2">
await Sinco.evaluatePage(() => {
  return document.getElementById("username").getAttribute("user_id") // "2"
})

@ebebbington
Copy link
Member Author

ebebbington commented Dec 13, 2021

can add it to element class? eg

function attribute(name: string) {
  send("document.querySelector(this.selector)[name]
}

@ebebbington
Copy link
Member Author

Following v4, it should be:

async function attribute(name: string, value?: string) {
  if (value) {
    return await this.#page.evaluate(`${this.method}('${this.selector}').setAttribute('${name}', '${value}')`)
  }
  return await this.#page.evaluate(`${this.method}('${this.selector}').getAttribute('${name}')`)
}

@ebebbington
Copy link
Member Author

or im thinking getAttribute and setAttribute to be more inline with the browser api

@ebebbington
Copy link
Member Author

Gonna try start working on this, this week

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

2 participants