R
R
rkfddf2020-08-28 20:08:48
Python
rkfddf, 2020-08-28 20:08:48

How to pass variable from python to javascript in Selinium?

How to pass variable from python to javascript in Selinium?

from selenium import webdriver
driver.get('https://bes.ua')
# дальше вычисляю переменную - удачно и пытаюсь прокрутить страницу
loc = int(loc)
driver.execute_script("window.scrollTo(0, loc )")

And I get the error selenium.common.exceptions.JavascriptException: Message: javascript error: loc is not defined

How to pass the variable correctly?

Answer the question

In order to leave comments, you need to log in

1 answer(s)
0
0ralo, 2020-08-28
@rkfddf

I'm not sure, but you seem to be passing the variable name, try

driver.execute_script(f"window.scrollTo(0, {loc})")

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question