"Element Not Interactable" Error using Selenium on a clickable object - python

I'm new to using Selenium with Python. I'm trying to click on this sign-in button on glassdoor: Glassdoor Sign-in Button
Actual: Using both the XPATH and the classname "LockedHomeHeaderStyles__signInButton", I keep getting the "ElementNotInteractableException" thrown.
Expected: I should be able to select the element and click it.
When I open the site and try to manually click the button myself, I am able to do this. Am I doing something wrong in my code?
def sign_in():
sign_in_element = WebDriverWait(driver, 10).until(
EC.presence_of_element_located((By.CLASS_NAME, "LockedHomeHeaderStyles__signInButton"))
)
sign_in_element.click();

There are two button element with "Sign In" text. You need second one. Try using the below xpath-
//button[text()="Sign In" and not(contains(#class,"d-flex"))]

Related

Get element from CQ class using Selenium

I want to enter the "Symbol" name and select tab "NSE" from the filter. Once that is done, click on table view button using Selenium. But I cannot find any of these nodes using Debugger.
(https://i.stack.imgur.com/uOrQc.png)
The original class "chart-frame" is found.
driver.find_element(By.ID, "chart-iframe")
I get "No such element" for any of the below commands. I cannot find any information on this CQ tags online.
driver.find_element(By.CLASS_NAME, "ciq-search")
driver.find_element(By.CSS_SELECTOR, "ciq-search")
driver.find_element(By.CSS_SELECTOR, "ciq-DT.tableview-ui")
driver.find_elements(By.XPATH, '//button')
Firstly, you need to switch into that iframe to scrape whatever you wanna scrape. You can use following code snippet for it:
iframe = driver.find_element(By.XPATH, "//iframe[#name='TheIframeName']")
driver.switch_to.frame(iframe)
You can use driver.switch_to.default_content() to switch back to default content.

SELENIUM PYTHON ElementClickInterceptedException:

I'm writing a Selenium Python script. Unfortunately, I can't click "Sign in" button or check mark.
I've tried many ways. I'll be glad if anyone helps me plz.
Link:
https://stagingskateontario.memberlounge.ca/auth/login
My Code:
wait.until(EC.element_to_be_clickable((By.ID, ":r2:")))
driver.find_element(By.ID,":r2:").click()
Error:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (790, 723)
(Session info: chrome=103.0.5060.134)
enter image description here
I was able to click the button with javascript
element = browser.find_element_by_xpath("/html/body/div/main/div/div/div[2]/form/button")
browser.execute_script("arguments[0].click();", element)
JavaScriptExecutor is an Interface that helps to execute JavaScript through Selenium Webdriver. JavaScriptExecutor provides two methods “executescript” & “executeAsyncScript” to run javascript on the selected window or current page.

Selenium Python Can't click button: ElementNotInteractable or StaleElementReferenceException

I'm trying to automate MS Teams and can't get past the login because after entering the password I am having issues clicking the Sign In button.
If I try:
button = driver.find_element_by_xpath('//*[#id="idSIButton9"]')
button.click()
I get:
ElementNotInteractableException: Message: element not interactable.
If I try to solve it with Action Chains method (which seems to have solved many similiar issues for lots of people):
button = driver.find_element_by_xpath('//*[#id="idSIButton9"]')
driver.implicitly_wait(10)
ActionChains(driver).move_to_element(button).click(button).perform()
I get:
StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
It is worth mentioning that when logging in manually I can get past this stage with pressing return after entering my password but I couldn't be successful with send keys methods neither.
If you still filled the form use submit() function - It is there to make your life easier.
Import webdriver:
from selenium import webdriver
Create webdriver object:
driver = webdriver.Firefox()
Get the website:
driver.get("https://www.YOUR_WEBSITE.de/")
Get element - In your case input for password
element = driver.find_element_by_xpath('//*[#id="i0118"]')
Send keys - Enter password
element.send_keys("YOUR_PASSWORD")
Submit contents
element.submit()
The element which you are trying to locate using the XPath driver.find_element_by_xpath('//*[#id="idSIButton9"]') might be the part of the previous screen and new screen, hence the driver might be referring to the element which is part of the previous screen, hence you are getting the StaleElementReferenceException.
The simplest way to resolve this is you can add, driver.refresh() just before the above xpath, this will load the page and DOM with the new elements.
Else, you can use a different locator strategy which will uniquely identify that element.

Unable to locate element in Python Selenium webdriver find_element_by_xpath

i'm trying to click the "download Results" button on this website .
i'm using below python code to click this button
from selenium import webdriver
chromedriver_path = 'E:/software/python/chromedriver'
url = 'https://www.cms.gov/apps/physician-fee-schedule/search/search-results.aspx?Y=0&T=4&HT=2&CT=3&H1=74750&H2=74800&M=5'
driver= webdriver.Chrome(executable_path=chromedriver_path )
driver.get(url)
driver.find_element_by_xpath('//*[#title="Download Results"]').click()
i'm getting below error
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//frame[#name="aspnetForm"]"}
(Session info: headless chrome=83.0.4103.116)
i'm thinking if the button is within a iframe but how do I find out the iframe?
This may help you out: Unable to locate element using selenium webdriver in python
Try and switch to the frame first, and then search for the element.
i realized that there's a agreement page that i need to click 'Agree' button first.
i didn't see this in browser because i already clicked 'Agree' weeks ago. but in webdriver, i need to click that each time.
Just after the URL opens, a page comes up asking you to agree the terms. You need to click on that Agree first. Since it is possible that once clicking on the Agree button, it won't come again if you accepted it on default browser. So just be sure with code, you can first check the presence of the agree button first.
This kind of function you may make to check presence:
def elementPresent(locatorType, locator):
#present = true
#not present = false
wait = WebDriverWait(driver, 20)
try:
wait.until(EC.presence_of_element_located((locatorType, locator)))
except Exception:
return False
return True
And then using if condition you may proceed further like:
if(elementPresent("xpath", "//a[#title='Accept']/span")):
driver.find_element_by_xpath("//a[#title='Accept']/span").click()
and then you may click on the element you want, there is no frame that is required to be switched to.
driver.find_element_by_xpath("//a[#title = 'Download Results']/span").click()
Just extract the element and click on it and your required file will be downloaded.

How to press a button with selenium and xpath

I need to press a button from a webpage with selenium,but that button has no id.
Other buttons from same webpage are having an id so no problem with pressing that ones with following code:
driver.find_element_by_id('some_id').click()
When i use firebug and firepath on that problem button output is:
<span class="linkRosso"> Invia truppe</span>
xpath:
html/body/div[6]/div[1]/div/div[3]/div/div[2]/table/tbody/tr/td[1]/a[3]/span
Is this information useful??
Use find_element_by_xpath.
xpath = 'html/body/div[6]/div[1]/div/div[3]/div/div[2]/table/tbody/tr/td[1]/a[3]/span'
driver.find_element_by_xpath(xpath).click()

Categories

Resources