TypeError: 'WebElement' object is not subscriptable

前端 未结 3 2002
灰色年华
灰色年华 2021-01-24 02:43

I try to press the Replay button at Spotify Web Player with Python, but get this error. How can I press buttons in a webplayer?

replay = driver.find_element_by_xp         


        
3条回答
  •  刺人心
    刺人心 (楼主)
    2021-01-24 03:02

    As @KunduK commented remove the [0].

    You are using absolute xPath this is not recommended.

    Try using relative xPath...

    If there are a few buttons and you need the first use the [0] in the xpath like so:

    replay = driver.find_element_by_xpath("""/html/body/div[2]/div/div[4]/div[3]/footer/div/div[2]/div/div[1]/div[5]/button[0]""")
    replay.click() 
    

提交回复
热议问题