如何获取按钮内的html元素?

时间:2019-10-28 10:57:15

标签: python selenium

<button type="button" name="abc" id="abc" class="bp" onmouseover="this.className = 'bp bph'" onmouseout="this.className = 'bp'" onclick="oCV_NS_.promptAction('finish')" style="font-family:&quot;Arial&quot;;font-size:9pt">
<span tabindex="0">GENERATE REPORT</span>

</button>

我想单击此按钮并尝试输入少量代码,但没有任何效果 尝试过:

driver.find_element_by_id("abc").click();

driver.find_element(By.ID, "abc")

element_by_name也尝试过

2 个答案:

答案 0 :(得分:0)

请尝试以下代码,并检查按钮是否不属于iframe:

from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

browser = webdriver.Chrome()
wait = WebDriverWait(browser, 10)
button= wait.until(EC.visibility_of_all_elements_located((By.ID, "abc")))
button.click()

答案 1 :(得分:0)

尝试与以下xpath一起使用:

driver.find_element_by_xpath("//button[@id='abc']/span").click()