我有以下代码:
for i in range(69,96,1):
loztreeid = "loztree_" + str(i) + "_check"
driver.find_element_by_id(loztreeid).click()
time.sleep(0.5)
我需要点击名为loztree_69_check
的ID到loztree_95_check
。当我尝试使用上面的代码时,它给出了以下错误:
File "gpsdemo.py", line 41 driver.find_element_by_id(loztreeid).click()
最佳答案
我找到了一种方法,尝试使用下面的代码并且工作正常:
for i in range(69,96,1):
driver.find_element_by_id('loztree_' + str(i) + '_check').click()
我不知道为什么双引号("
)不起作用,只需更改为单引号('
)即可。
关于python - 如何使用变量 driver.find_element_by_id 的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51530240/