繁体   English   中英

单击我在python中找不到硒的按钮

[英]clicking on a button i cant find with selenium in python

我有这个html元素:

<button class="expedition_button awesome-button " onclick="attack(null, '6', 2, 0, '')"><div></div><div></div></button>

并且由于某种原因我无法单击它...只是给我一个关于不按类查找元素的错误...

有没有一种方法可以发送按钮“ onclick”按钮功能的信息? 即向该按钮的功能发送信息-“ attack(null,'6',2,0,'')”

或使用此信息查找按钮

尝试过xpath但我似乎找不到它..只是给了我这个:

selenium.common.exceptions.NoSuchElementException: Message: Unable to locate element: /html/body/div[2]/div/div[3]/div/div[2]/div[2]/div[2]/div[2]/div[2]/button

当我检查xpath时,每次打开页面时都会看到它的变化。

第一 第二 THRID

我想您有一个具有唯一ID'expedition_info1'的div元素。 您可以使用xpath轴来单击与该div元素相关的button 尝试:

driver.find_element_by_xpath("//div[@id='expedition_info1']/following-sibling::*[1]/button")// to click on 1st button element.

好的,所以我尽可能地将它们组合在一起,因为我没有使用Python编写代码,所以我的语法在某些地方可能不正确,但是我试图做到正确,无论哪种情况都存在逻辑和注释应该解释我在做什么:

首先让我们获取容器div:

//Get the container which holds the 4 divs and their buttons
containerDiv = browser.find_element_by_id('expedition_list')

//Get the divs which contain the buttons
containerDivs = containerDiv.find_elements_by_class_name('expedition_box')

//Iterate the containers
for val in containerDivs:
    //Get the div elements of the container
    childDivs = val.find_elements_by_tag_name('div')
    //iterate these divs, looking for the one which contains a button
    for val1 in childDivs
       buttonDiv = val1.find_elements_by_tag_name('button')
       //Check to see if we found a div with a button
       if len(buttonDiv) > 0
          for button in buttonDiv
          //If the button text is what we are looking for, click it
          if button.Text = 'whatever your button's text is'
             button.Click

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM