[英]Selenium(PYTHON) add variable that converts number into syntax
So i have a code that changes the text of a class, but instead of manually entering the number, i would like the number to be equal to whatever X is, and convert that number into a string if thats what needs to be done所以我有一个代码可以更改 class 的文本,但我不想手动输入数字,而是希望数字等于 X 是什么,如果需要的话,将该数字转换为字符串
try:
newButton = WebDriverWait(driver, 100).until(
EC.presence_of_element_located((By.CLASS_NAME, "btn-full")))
finally:最后:
driver.execute_script('arguments[0].innerHTML = "X";', newButton)
driver.execute_script("arguments[0].setAttribute('class','NEWBUTTON')", newButton)
How do i make sure its made in such a way that it takes a variable that holds an integer value, and its written out in place of the X我如何确保它以这样的方式制作,即它采用一个包含 integer 值的变量,并用它代替 X
Well you can pass it as arguments[1]
like this:好吧,您可以像这样将其作为
arguments[1]
传递:
x = #some number
driver.execute_script('arguments[0].innerHTML = arguments[1];', newButton, x)
If you want it to be an int
you can leave it as it is, but if you want it as a string
then just convert it wherever you want and pass it into the method.如果您希望它是一个
int
,您可以保持原样,但如果您希望它是一个string
,那么只需将它转换成您想要的任何位置并将其传递给方法即可。
The arguments[n]
is the (n+2)'nd argument you pass into the method execute_script()
. arguments[n]
是您传递给方法execute_script()
的第 (n+2) 个参数。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.