here is my code:
this all_plus_icons returns a list of 10 elements of the page which I need to wait until all these elements are clickable in selenium and click each of them.
all_plus_icons = driver.find_elements_by_xpath("//*[#id='block-views-tenders-block']/div/div/div[2]/div//div[1]/h5/span/i")
for i in all_plus_icons:
time.sleep(10)
i.click()
the above code sometimes generates an error as :
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <i class="ic ac-icon-add"></i> is not clickable at point (831, 605). Other element would receive the click: <div class="cc_banner cc_container cc_container--open">...</div>
(Session info: chrome=87.0.4280.88)
I used this :
WebDriverWait(driver , 20).until(EC.element_to_be_clickable((By.XPATH , "//*[#id='block-views-tenders-block']/div/div/div[2]/div//div[1]/h5/span/i")))
but it does not work. how can I make sure all the elements are clickable.
this is the website.enter link description here
It seem that you need to accept Cookies to perform your actions. Try to do this first before clicking elements:
driver.find_element_by_link_text('Got it!').click()
WebDriverWait(driver , 20).until_not(EC.presence_of_element_located((By.CLASS_NAME , "cc_banner")))
Try run this code
for i in all_plus_icons:
time.sleep(10)
i.click()
driver.refresh
Related
I'm trying to find an element by it's id, click on it and download a file.
driver.get(url);
driver.implicitly_wait(60);
time.sleep(3)
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "ContentPlaceHolder1_a1")))
href = element.get_attribute('href')
value = href.split('/')[-1]
print(value);
element.click(); # Error
Error
element click intercepted: Element is not clickable at point (110, 1003)
I've tried Xpath, and CSS path too. All give the same error. If I check for the visibility then it times out. But I can manually see that the element is visible
element = WebDriverWait(driver, 10).until(EC.visibility_of_element_located((By.XPATH, "//a[contains(text(), 'text of the link')]")))
At last, I tried this code.
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "ContentPlaceHolder1_a1")))
ActionChains(driver).move_to_element(element).click().perform()
But it gives error
selenium.common.exceptions.MoveTargetOutOfBoundsException: Message: move target out of bounds
While identified the element, page is still loading, may be the reason it is clicking on somewhere else.
Scroll down to the element and then wait for 1 to 2 seconds and then click.
It is working perfectly for me.
element = WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.ID, "ContentPlaceHolder1_a1")))
element.location_once_scrolled_into_view #scroll down to element
time.sleep(2) # wait for 2 seconds , 1 sec working as well
element.click()
I am trying to click on the "Next page" in Python-Selenium. The element and its path are seen, the buttom is being clicked but after clicking an error is shown:
"StaleElementReferenceException:stale element reference: element is not attached to the page document"
My code so far:
element = WebDriverWait(driver, 20).until(EC.presence_of_element_located(\
(By.XPATH, butn)))
print (element.is_enabled())
while True and element.is_enabled()==True:
driver.find_element_by_xpath(butn).click()
The error is one element.is_enabled()==True after clicking
Can someone help?
When you search elements in Selenium then it doesn't keep full objects but only references to objects in DOM in browser. And when you click then browser creates new DOM and old references are incorrect and you have to find elements again.
Something like this
# find first time
element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, butn)))
print(element.is_enabled())
while element.is_enabled():
driver.find_element_by_xpath(butn).click()
# find again after changes in DOM
element = WebDriverWait(driver, 20).until(EC.presence_of_element_located((By.XPATH, butn)))
print(element.is_enabled())
I've been searching around the site but can not seem to find a fix that works for me. I am trying to click a button that should load more reviews.
driver.get("https://www.mediamarkt.nl/nl/product/_philips-essential-airfryer-xl-hd9260-90-1653991.html")
WebDriverWait(driver, 20).until(EC.element_to_be_clickable((By.CSS_SELECTOR, ".bv-content-btn-pages-load-more"))).click()
Is the code I am using. This results in an error:
selenium.common.exceptions.ElementClickInterceptedException: Message: Element <button class="bv-content-btn bv-content-btn-pages bv-content-btn-pages-load-more bv-focusable" type="button"> is not clickable at point (674,670) because another element <div class="gdpr-cookie-layer gdpr-cookie-layer--show"> obscures it
I've tried getting the element and then clicking it:
element = driver.find_element_by_class_name('bv-content-btn-pages-load-more')
driver.execute_script("arguments[0].click();", element)
I also tried doing it using an action chain:
element = driver.find_element_by_class_name('bv-content-btn-pages-load-more')
ActionChains(driver).move_to_element(element).click().perform()
What is the actual issue here and how do I fix it?
WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
(By.CSS_SELECTOR, '[class="gdpr-cookie-layer__btn gdpr-cookie-layer__btn--submit gdpr-cookie-layer__btn--submit--all"]'))).click()
WebDriverWait(driver, 20).until(EC.element_to_be_clickable(
(By.CSS_SELECTOR, ".bv-content-btn-pages-load-more"))).click()
you have to first close the accept cookie dialogue , else selenium cannot click the load more element as the accept_cookie screen is in forground
I need help. I am trying to click an element in Selenium Python, but I get the following message:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point (318, 450). Other element would receive the click:
driver.find_element_by_xpath('(//img[#decoding="auto"])[1]').click()
This is the XPath I created. Its the only node. The element is visible, I don't see any other element that can receive that click. I am torturing myself for a while now. Any help is appreciated. 🙏 The link from where I try to click that element https://www.instagram.com/explore/tags/bass/
EDIT: Thanks to pcalkins, I managed to find a workaround. here is the working code:
wait = WebDriverWait(driver, 100, poll_frequency=1)
pic = wait.until(EC.visibility_of_element_located((By.XPATH, '(//img)[2]')))
ActionChains(driver).move_to_element(pic).click().perform()
I have this code:
driver.switch_to.window(window_after)
try:
myElem = WebDriverWait(driver, delay).until(EC.presence_of_element_located((By.NAME, '_eventId_confirmed')))
print ("Page 2 is ready!")
except TimeoutException:
print ("Loading took too much time!")
btn = driver.find_element_by_name('_eventId_confirmed')
btn.click()
as you can see I first switch window and then check for an element, get that element (a button) and finally try to click on said button. This works maybe 2 out of 3 times but ever so often does it fail with this error message
selenium.common.exceptions.ElementNotInteractableException: Message: Element <button class="btn" name="_eventId_confirmed"> could not be scrolled into view
When visually looking at the flow when it is executing everything seems fine (my first guess was that the window switch didn't work as expected) and the browser ends up in the expected state where I am able to manually click this button. Interestingly enough, there is no timeout or similar when this error occurs, it happens instantly during execution.
Any ideas what's going on here?
This problem usually arises when the element you are trying to click is present on the page but it is not fully visible and the point where selenium tries to click is not visible.
In this case, you can use javascript to click on the element, which actually operates directly on the html structure of the page.
You can use it like:
element = driver.find_element_by_name("_eventId_confirmed")
driver.execute_script("arguments[0].click();", element)
As your final step is to invoke click() on the desired element, so instead of using the expected_conditions as presence_of_element_located() you need to use element_to_be_clickable() as follows:
try:
myElem = WebDriverWait(driver, delay).until(EC.element_to_be_clickable((By.NAME, '_eventId_confirmed')))
Here are the 2 options.
Using selenium location_once_scrolled_into_view method:
btn.location_once_scrolled_into_view
Using Javascript:
driver.execute_script("arguments[0].scrollIntoView();",btn)
Sample Code:
url = "https://stackoverflow.com/questions/55228646/python-selenium-cant-sometimes-scroll-element-into-view/55228932? noredirect=1#comment97192621_55228932"
driver.get(url)
element = driver.find_element_by_xpath("//a[.='Contact Us']")
element.location_once_scrolled_into_view
time.sleep(1)
driver.find_element_by_xpath("//p[.='active']").location_once_scrolled_into_view
driver.execute_script("arguments[0].scrollIntoView();",element)