Issue
I am new to python selenium and I am trying to click on a button with this structure
<div id="mceu_32" class="mce-container mce-flow-layout-item mce-last mce-btn-group" role="group"><div id="mceu_32-body"><div id="mceu_15" class="mce-widget mce-btn mce-first mce-last" tabindex="-1" role="button" aria-label="Clear formatting"><button id="mceu_15-button" role="presentation" type="button" tabindex="-1"><i class="mce-ico mce-i-removeformat"></i></button></div></div></div>
<div id="mceu_32-body"><div id="mceu_15" class="mce-widget mce-btn mce-first mce-last" tabindex="-1" role="button" aria-label="Clear formatting"><button id="mceu_15-button" role="presentation" type="button" tabindex="-1"><i class="mce-ico mce-i-removeformat"></i></button></div></div>
<div id="mceu_15" class="mce-widget mce-btn mce-first mce-last" tabindex="-1" role="button" aria-label="Clear formatting"><button id="mceu_15-button" role="presentation" type="button" tabindex="-1"><i class="mce-ico mce-i-removeformat"></i></button></div>
<button id="mceu_15-button" role="presentation" type="button" tabindex="-1"><i class="mce-ico mce-i-removeformat"></i></button>
<i class="mce-ico mce-i-removeformat"></i>
I tried
btn = browser.find_element_by_css_selector('i.mce-ico mce-i-removeformat')
and
btn = browser.find_element_by_id("mceu_15-button")
and
btn = browser.find_element_by_class_name("mce-ico mce-i-removeformat")
but I end up with the same error "NoSuchElementException"
Solution
You can try this code:
from selenium import webdriver as wd
from selenium.webdriver.chrome.options import Options
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
# settings for chrome
chrome_options = Options()
# Private browsing
chrome_options.add_argument("--incognito")
driver = wd.Chrome(executable_path='chrome/chromedriver.exe', options=chrome_options)
button_tag = WebDriverWait(driver, 30).until(EC.visibility_of_element_located((By.CSS_SELECTOR, "#mceu_15-button")))
button_tag.click()
Answered By - Metalgear
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.