单击一个按钮以在 python selenium 中显示一个文本框
Click a button to display a text box in python selenium
我正在尝试单击取消隐藏另一个文本框的按钮。单击按钮更改脚本
<span id="incident.u_brand_edit" style="display: none;">
到
<span id="incident.u_brand_edit" style>
下面是按钮HTML
<button class="btn btn-default btn-ref" type="button" aria-labelledby="incident.u_brand_title_text"
data-target="#incident\.u_brand" title="" tabindex="0" id="incident.u_brand_unlock"
data-type="glide_list_unlock" data-ref="incident.u_brand" data-auto-close="false"
data-placement="auto" style="margin-right: 5px;" list-read-only="false"
data-original-title="Unlock Brand"><span class="icon icon-locked" aria-hidden="true"></span></button>
我正在尝试使用以下代码实现此目的
driver.find_element_by_id("incident.u_brand_unlock").click()
也试过这个
driver.find_element_by_id("incident.u_brand_unlock").send_keys("\n")
以上代码针对的是按钮,但没有点击,文本框也没有取消隐藏,无法进行进一步的操作。
尝试在您的代码中使用 ActionChains class,如下所示 -
# Import
from selenium.webdriver import ActionChains
wait = WebDriverWait(driver, 5)
action = ActionChains(driver)
Button_Click = wait.until(EC.element_to_be_clickable((By.ID, 'incident.u_brand_unlock')))
action.move_to_element(Button_Click).click().perform()
点击需要诱导的元素 for the element_to_be_clickable()
and you can use either of the following :
使用CSS_SELECTOR
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn.btn-default.btn-ref[id$='u_brand_unlock'][data-original-title='Unlock Brand']>span"))).click()
使用XPATH
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn btn-default btn-ref' and contains(@id, 'u_brand_unlock')][@data-original-title='Unlock Brand']/span"))).click()
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC
在这个中找到答案。不得不删除我想要出现的字段的样式属性。
我正在尝试单击取消隐藏另一个文本框的按钮。单击按钮更改脚本
<span id="incident.u_brand_edit" style="display: none;">
到
<span id="incident.u_brand_edit" style>
下面是按钮HTML
<button class="btn btn-default btn-ref" type="button" aria-labelledby="incident.u_brand_title_text"
data-target="#incident\.u_brand" title="" tabindex="0" id="incident.u_brand_unlock"
data-type="glide_list_unlock" data-ref="incident.u_brand" data-auto-close="false"
data-placement="auto" style="margin-right: 5px;" list-read-only="false"
data-original-title="Unlock Brand"><span class="icon icon-locked" aria-hidden="true"></span></button>
我正在尝试使用以下代码实现此目的
driver.find_element_by_id("incident.u_brand_unlock").click()
也试过这个
driver.find_element_by_id("incident.u_brand_unlock").send_keys("\n")
以上代码针对的是按钮,但没有点击,文本框也没有取消隐藏,无法进行进一步的操作。
尝试在您的代码中使用 ActionChains class,如下所示 -
# Import
from selenium.webdriver import ActionChains
wait = WebDriverWait(driver, 5)
action = ActionChains(driver)
Button_Click = wait.until(EC.element_to_be_clickable((By.ID, 'incident.u_brand_unlock')))
action.move_to_element(Button_Click).click().perform()
点击需要诱导的元素element_to_be_clickable()
and you can use either of the following
使用
CSS_SELECTOR
:WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn.btn-default.btn-ref[id$='u_brand_unlock'][data-original-title='Unlock Brand']>span"))).click()
使用
XPATH
:WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn btn-default btn-ref' and contains(@id, 'u_brand_unlock')][@data-original-title='Unlock Brand']/span"))).click()
注意:您必须添加以下导入:
from selenium.webdriver.support.ui import WebDriverWait from selenium.webdriver.common.by import By from selenium.webdriver.support import expected_conditions as EC
在这个