1

I need to rewrite a existing function which is created by the website when the page is loaded. The function is something like this:

function CheckStatus() {
    var vcode = $.trim($("#insertCode").val()).toUpperCase();
    var vreturn = encodeURIComponent(document.getElementById('text_return').value);
... (lots of other stuff)
}

And I would like to rewite this function to be like this:

function CheckStatus() {
 return true;
}

If I paste this function in the chrome console, it rewrites with no problem. But when I try to do it with selenium It does not rewrite... I think it creates another function with the same name. My code in python using selenium webdriver is this:

driver.execute_script("function CheckStatus() { return true;}")

It does not return errors. Nothing happens actually.

Any clues how to solve this with selenium?

Thanks!

3 Answers 3

1

Solve it with something similar:

driver.execute_script("CheckStatus = function CheckStatus() { return true;}")

Thanks guys!

Sign up to request clarification or add additional context in comments.

Comments

0

You're sending a function declaration. Nothing is executed here because you didn't ask to execute anything, you just defined a function. What you want looks more like this:

driver.execute_script("() => ({ return true;})()")

Don't forget to actually call you function at the end.

Comments

0

i'm not sure, but try to set the function to window object, maybe python's selenium has another name space

so:

driver.execute_script("window.CheckStatus = () => true;")

Comments

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.