selenium.common.exceptions.JavascriptException: Message: ReferenceError: variable is not defined

Question:

'    ct1 = df2[(df2['HomeTeam'] == at1)]['AwayTeamScore'].to_string(index=False)
result_away = np.round(ct1, decimals=3)'

output: ‘0.938031’

When executing the below code,

'javaScript1 = "document.getElementById('PoissonForm_homeGoalExp').value = result_away"'

output:

selenium.common.exceptions.JavascriptException: Message: ReferenceError: result_away is not defined

How can I able to send the value as correctly defined as ‘result_away’?

Asked By: GP89853

||

Answers:

You can execute the javascript using execute_script.

javaScript1 = f"document.getElementById('PoissonForm_homeGoalExp').value = {result_away}"
driver.execute_script(javaScript1)
Answered By: Himanshu Poddar