selenium.common.exceptions.WebDriverException: Message: unknown error: 'script' must be a string while using execute_script() through Selenium Python

后端 未结 3 1334
温柔的废话
温柔的废话 2021-01-25 14:41

I\'ve got an issue with browser.execute_script while using selenium with python. There is an element that i\'d like to click (it\'s xpath below)

\"//*[@id=\'lis         


        
3条回答
  •  再見小時候
    2021-01-25 15:04

    The correct way to execute a script is to actually write a JavaScript script!.

    The click() function of selenium is on the element of the DOM you have located not a script.

    As @Andersson suggested try browser.execute_script('arguments[0].click();', navMenu)

    I can see you added a sleep for 3 seconds... Using Selenium we generally use WebDriverWait you can learn more about wait's here.

    If it's too complicated you can just start with driver.implicitly_wait(3) instead of sleep.

    Edit:

    If the Element is not displayed yet you can just use navMenu.is_displayed()

    Hope this helps you.

提交回复
热议问题