To identify the submit button with text as Post Discussion you can use either of the following Locator Strategies:
Using CSS_SELECTOR
:
element = driver.find_element_by_css_selector("button.btn_green_white_innerfade.btn_medium[id^='commentthread_General_'][id$='_submit']>span")
Using XPATH
:
element = driver.find_element_by_xpath("//button[@class='btn_green_white_innerfade btn_medium' and starts-with(@id, 'commentthread_General_')]/span[text()='Post Discussion']")
However, as it is a submit button so moving ahead you will invoke click()
on it, so you have to induce WebDriverWait for the element_to_be_clickable()
and you can use either of the following solutions:
Using CSS_SELECTOR
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, "button.btn_green_white_innerfade.btn_medium[id^='commentthread_General_'][id$='_submit']>span"))).click()
Using XPATH
:
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.XPATH, "//button[@class='btn_green_white_innerfade btn_medium' and starts-with(@id, 'commentthread_General_')]/span[text()='Post Discussion']"))).click()
Note : You have to add the following imports :
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
from selenium.webdriver.support import expected_conditions as EC