2

Hey here is my async js function that i want to execute and return the value .

async function matcheslol() {
    let allmatches=[]
    let matches = document.getElementsByClassName('EventCellstyles__Link-sc-1m83enb-0 dhKVQJ')
    for (i = 0; i < matches.length; i++) {
        let details = (matches[i].innerText).split('\n').slice(2, 4);
        let matchname = details.join(' - ');
        console.log(matchname)
        matches[i].firstChild.click()
        await sleep(3000)
        let votes = document.getElementsByClassName('styles__VotingWrapper-sc-1f9zoyc-1 iOsjnp')[0].innerText.split('\n').slice(0,3)
        let date = document.getElementsByClassName('styles__Wrapper-sc-1c9nn5b-0 HoJZc ps ps--active-y')[1].getElementsByClassName('Content-sc-1o55eay-0 gYsVZh')[0].innerText
        let dict={'DATE':date,'MatchTitle':matchname,'Votes':votes}
        allmatches.push(dict)
    }
    return allmatches
}
function sleep(ms) {
    return new Promise(resolve => setTimeout(resolve, ms));
  }
  
matcheslol()

Python :

data=driver.execute_async_script(script_mentioned_above)

I get this error: selenium.common.exceptions.TimeoutException: Message: script timeout

1 Answer 1

1

The way I do it:

# Create the script you want
my_script = '''
async function matcheslol() {
  // Your previous function here...
}

// Set it to window so we can use it later
window.matcheslol = matcheslol;
'''

# Set window variable
driver.execute_script(my_script)
# Execute the function and return the value
value = driver.execute_script('return window.matcheslol().then(r => r);')
Sign up to request clarification or add additional context in comments.

1 Comment

What if I don't want the value to be globally acessible?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.