Page 1 of 1

Selenium - Executescript passing variable

Posted: 23 May 2020, 13:59
by Axxi
Hi!

Im trying to replace "hello world" below with a variable, but I just cant find the way to do so, i always get an error probably because the code is just wrong.

driver.executeScript("arguments[0].setAttribute('value', 'hello world')", driver.FindElementsbyXpath("//input[@name='InvoiceItemNumber']"))

Does anyone have any exeperience with this being possible at all?


Thanks in advance!

Re: Selenium - Executescript passing variable  Topic is solved

Posted: 23 May 2020, 15:52
by Xtra

Code: Select all

var := "hello world"
element := driver.FindElementsbyXpath("//input[@name='InvoiceItemNumber']")
driver.executeScript("arguments[0].setAttribute('value', '" . var . "');", element)

Re: Selenium - Executescript passing variable

Posted: 24 May 2020, 06:33
by Axxi
Thank you so much, works like a charm. Much appreciated !



Xtra wrote:
23 May 2020, 15:52

Code: Select all

var := "hello world"
element := driver.FindElementsbyXpath("//input[@name='InvoiceItemNumber']")
driver.executeScript("arguments[0].setAttribute('value', '" . var . "');", element)

Re: Selenium - Executescript passing variable

Posted: 06 Jun 2021, 10:00
by SeeYouAtTop
I want to get value instead of set value, What I need to change in code?

In the hope of Reply :)
Xtra wrote:
23 May 2020, 15:52

Code: Select all

var := "hello world"
element := driver.FindElementsbyXpath("//input[@name='InvoiceItemNumber']")
driver.executeScript("arguments[0].setAttribute('value', '" . var . "');", element)