I'm trying to click to close a message from a website with selenium. However, when I put it to click, a message appears in the Visual Studio Code console saying that it was not possible to click on the element because it is not a clickable element.
sleep(5)
web.find_element(By.XPATH, '//*[#id="top-container"]/div[1]/div/i').click()
devtool element
error https://i.stack.imgur.com/sgzoE.png
if anyone knows any library that delete the element in devtool. why do i need to remove that message to appear another button to proceed with application
If you look at the error message carefully, it doesn't state that it's not a clickable element. It states that the click was intercepted. In other words, Selenium tried to click on the X to close but another element, an <h3>, got in the way.
It looks like your locator is fine. According to the error message, it looks like it's finding the right element. I personally would change it to
web.find_element(By.CSS_SELECTOR, 'i.icon-remove').click()
because I think it's more readable and less likely to click the wrong element.
I can't see the page so I have no idea what h3 is getting in the way and if it's possible to even remove it. So, if you can't get around the h3, you will likely have to use JS to click the element.
icon = web.find_element(By.CSS_SELECTOR, 'i.icon-remove')
driver.execute_script("arguments[0].click();", icon)
There are different ways to call an element. Let's try the following:
web.find_element(By.ID, "top-container").click()
Please let me know if works, either way we can see other options
So I am trying to write a code to automatically join a google meet. So I need to sign into my google account, which runs all fine but when I get to "Verify that it's you" (image 1), and I try to use driver.get it takes me back to the original sign-in page (image 2)
How can I click on the "Continue" button without using driver.get/without getting taken back to the original sign-in page. I know that all I have to do is click on the "Continue" because when I do it manually it works perfectly. Pressing "Tab" and then "Enter" would also work, but it seems you need to use driver.get as well. Thank you
so i think you don't understand driver.get() usage. it is used only to make the browser browse to a specific link which you can specify before hand. what you have to do here is open the google meet page manually and go to your required page where you want to click the button. right click on the button and click on inspect. then go to the higlighted code and locate the button you want and right click on copy and select xpath from the list. now coming to your code.
add this line:
element=driver.find_element_by_xpath('_xpath')
element.click()
replace _xpath with the long string you copied (which is the xpath of the button you want to click).
this is the way to click on buttons or text boxes or anything you name it in selenium.
**beware of one thing. don't make your code click immediately. if the page does not fully load and the click is made then the 1st line will throw an element not found error. put some kind of delay till page loads or use a while loop and exception handling to wait till the element is found
This one should work for you
userName = driver.find_element_by_xpath("//button[#name='username']")
driver.execute_script("arguments[0].click();", userName)
This question already has answers here:
Selenium - wait until element is present, visible and interactable
(6 answers)
Closed 1 year ago.
I am using Selenium with Python to automate a process to upload a file. There is an "Upload" button which is disabled by default and only becomes clickable when the file to be uploaded is chosen.
The HTML for Disabled Button is -
<button type="button" id="upload-button" data-bi-id="upload-button" class="ms-Button ms-Button--primary is-disabled root-296" disabled="" aria-label="Upload" aria-disabled="true" data-is-focusable="false">
And the HTML for button after it becomes clickable is -
<button type="button" id="upload-button" data-bi-id="upload-button" class="ms-Button ms-Button--primary root-437" aria-label="Upload" data-is-focusable="true" tabindex="0">
I am using -
WebDriverWait(browser, 15).until(EC.element_to_be_clickable((By.ID,"upload-button"))).click()
But its not working. I believe this is clicking on the disabled button (even though the file is chosen and the button has become clickable). I also tried -
WebDriverWait(browser, 15).until(EC.element_to_be_clickable((By.CLASS_NAME,"ms-Button ms-Button--primary root-437"))).click()
But this gives a TimeOut Exception. So what should I do to click this button after it becomes clickable. I have tried some solutions from the Internet, but none of them seem to be working.
Regarding the current version of your code, I think you may be right that it is clicking the button before it is really enabled. You have
WebDriverWait(browser, 15).until(EC.element_to_be_clickable((By.ID,"upload-button"))).click()
You are waiting for this element to be clickable. I wanted to try and figure out exactly what this meant so I looked at the source code. element_to_be_clickable is satisfied As soon as the element is "visible" and "enabled".
Visibility, I know, is defined as presence on the DOM and height/width both > 0. From your description it sounds like your button is immediately visible. So as soon as it is "enabled", element_to_be_clickable is satisfied and the wait will end.
This begs the question, what exactly determines whether an element is "enabled"? I found that selenium's is_enabled (which is required in the source code for element_to_be_clickable to pass), is essentially a negation of the W3C specification for disabled(). What it boils down to is this single line, which states that an element is "disabled" if The element is a button, input, select, textarea, or form-associated custom element, and the disabled attribute is specified on this element (regardless of its value).
That's it. Your element does have the "disabled" attribute, but it also has some other stuff that might cause it to be disabled -- the class name contains is-disabled, it's got aria-disabled="true" as well as data-is-focusable="false", all of which change by the time the button is fully clickable. I wonder if the disabled attribute goes away before something else that also causes the element to be disabled, so just as you said maybe your click is registering before the button is ready. To debug this I would try temporarily adding a hard wait, a few seconds long, after executing the WebDriverWait and before clicking the button.
For your class name,
WebDriverWait(browser, 15).until(EC.element_to_be_clickable((By.CLASS_NAME,"ms-Button ms-Button--primary root-437"))).click()
I suspect this is a dynamic class name, the root-437 part in particular, so maybe that's why that didn't work.
Finally, are you intending to upload from your filesystem by clicking the button? Because it can only interact with your web browser and can't browse a window on your OS, that doesn't work. There's a special way to upload files--you have to identify the file input element and send the absolute path of the file you want to upload to that element using send_keys().
It seems you are using wrong ID value.
WebDriverWait(browser, 15).until(EC.element_to_be_clickable((By.ID,"upload-button"))).click()
Or use this css selector
WebDriverWait(browser, 15).until(EC.element_to_be_clickable((By.CSS_SELECTOR,"#upload-button[data-is-focusable='true']"))).click()
As you can see, the button element while it is still disabled contains class is-disabled and contains attribute disabled and it doesn't contain these attributes when it is enabled.
So the expected condition is to locate the element defined by the following xpath:
//button[#id='upload-button' and(not(contains(#class,'is-disabled'))) and(not(#disabled))]
In other words you should use the following:
WebDriverWait(browser, 15).until(EC.presence_of_element_located((By.XPATH, "//button[#id='upload-button' and(not(contains(#class,'is-disabled'))) and(not(#disabled))]")))
You can locate the enabled button based on absence of one of the two attributes mentioned as well.
Try clicking without explicit wait, using implicit:
driver.implicitly_wait(15)
driver.find_element_by_xpath('//button[#data-is-focusable="true"]').click()
Or
driver.implicitly_wait(15)
driver.find_element_by_xpath('//button[#data-is-focusable="true" and #tabindex="0"]').click()
If this won't help, add more details to your question.
I am attempting to click on a button.
element.click() was not consistently clicking, so I tried to force a click driver.execute_script("arguments[0].click();", element). However, my force click doesn't click the button, but only highlights the borders of the button.
I suspected that perhaps the button was a dynamic element. But I tried accounting for that in my xpath.element.click() isn't consistent enough to use, but force click doesn't seem to be doing the trick.
I couldn't find any information about why a force click might not work, besides a dynamic element. Any ideas what might be going on?
driver.get("https://bi.prozorro.org/sense/app/fba3f2f2-cf55-40a0-a79f-b74f5ce947c2/sheet/HbXjQep/state/analysis")
element=WebDriverWait(driver, 60).until(EC.element_to_be_clickable((By.XPATH, "//th[#tid='st.header']//span[#title='Учасник']//following::th[#tid='st.header.search']")))
#element.click()
driver.execute_script("arguments[0].click();", element)
I am using python code such as below to click an element within an iframe on an angularjs page.
browser = webdriver.Ie()
browser.switch_to.frame('name')
browser.find_element_by_id('value').click()
After using click() I am unable to manually highlight text that appears on the page. Why might this happen? How can I restore the ability to highlight text with the mouse?
I have tried switching back to default content, but this makes no difference. Any ideas?
Other strange effects after using click(): Links and buttons don't work while using the mouse manually unless double-clicked. These would normally require single click. It is as if there is an invisible overlay blocking text selection or clicking links. Radio buttons and menus still work.
Edit: The site uses silverlight and I am wondering if this is related to the problem that results from using click().