通过find_element_by_xpath标识的元素返回selenium.common.exceptions.ElementNotVisibleException:消息:元素不可见

通过find_element_by_xpath标识的元素返回selenium.common.exceptions.ElementNotVisibleException:消息:元素不可见

问题描述:

点击按钮有问题.如果敌人在比赛中,则此按钮可以单击;如果敌人出局,则此按钮不能单击 开始 我尝试了这个:

I have problem with click button. This button can click if enemy is on play and can't click if enemy go out start I tried with this:

try:
    element= driver.find_element_by_xpath("//button[@class='butwb']")
    if element.is_displayed():       
        print ("Element found")
    else:
        print ("Element not found")
except NoSuchElementException:
    print("No element found") 

结果:

Element not found

如果我添加element.click():

selenium.common.exceptions.ElementNotVisibleException: Message: element not visible

我做错了什么?

与Kuncioso交谈并进入游戏后,我们发现有两个与他的定位器匹配的按钮,第一个被隐藏了.使用下面的代码单击了他想要的第二个按钮,解决了该问题.

After talking to Kuncioso and getting into a game, we found that there were two buttons that matched his locator and the first was hidden. The problem was solved using the code below to click the second button, the one he wanted.

driver.find_elements_by_xpath("//button[@class='butwb']")[1].click()