简体   繁体   中英

Selenium: How to click on a disabled button

I check button availability by xpath because button often change css class:

wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div[2]/main/div/div[2]/div[1]/div[2]/div[6]/button')))

But programm can`t find and click that button. Idk, can I use that method to be clickable, so maybe you know method how to find buttun w/o class/id.

It should wait until button will be clickable and click the button. full function:

try:
        wait = WebDriverWait(browser, 900)
        ButtBuy = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[1]/div/div[2]/main/div/div[2]/div[1]/div[2]/div[6]/button')))
    except:
        time.sleep(30)
        browser.quit()
    else:
        ButtBuy.click()
        wait = WebDriverWait(browser, 5)
        ButtConfirm = wait.until(EC.element_to_be_clickable((By.XPATH, '/html/body/div[8]/div/div/div[2]/button[2]')))
        ButtConfirm.click()

I think that xpath isn`t correct, but its correct, i paste xpath by xPath finder extension in Firefox browser, Maybe extension not correct generated xpath.

Button in the appointed time becomes available. And when the button becomes available, the program must click the button.

Html of the button:

按钮的html代码

HTML <button> disabled Attribute

The disabled attribute when present implies that the button should be disabled and a disabled button is unusable and un-clickable .

The disabled attribute is generally set to refrain a user from clicking on the button until some other condition has been met (like selecting a checkbox, etc). Then, a JavaScript could remove the disabled value, and make the button clickable again.

As per the HTML of the element

HTML

As the element is having the disabled attribute set you won't be able to click/interact with it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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