Python selenium code just stopped working [duplicate] - python

This question already has answers here:
Element MyElement is not clickable at point (x, y)... Other element would receive the click
(5 answers)
Closed 2 years ago.
I have been testing some code today and it has been working totally fine. It has now just stopped working, I haven't changed anything.
action.move_to_element(text_box)
action.click(text_box)
action.send_keys(index)
action.perform()
sleep(1)
driver.find_element_by_xpath('//*[#id="AC_tRes"]/li[1]').click()
sleep(10)
link = driver.find_element_by_link_text('Financials')
link.click()
This code enters a name into a search box and then goes to that page. It should then click on the Finance page.
It has been working totally fine. I haven't changed anything and now I get the following error:
selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element <a class="link3" href="foo" </a> is not clickable at point (505, 509)
But I don't understand why it would just stop when I haven't even edited the code.
https://www.marketscreener.com/MICROSOFT-CORPORATION-4835/
I land on this page and it should go to the Financial link. but it is sometimes working sometimes giving me the above error.

Sometimes site can take a while to load, way exceeding your sleep(10) call. Hence, the element might not be available for clicking when the line is executed.
You will want to read the docs on Waits, particularly around Expected Conditions, and rebuild your navigation with that mindset.

Related

Selenium ElementClickInterceptedException Error

I am working on this website
Basically I want to capture 2 latest news from News section that is below the table and store that news in some json and collect picture if possible but I am not able to go to the news section as It always raise error saying
selenium.common.exceptions.ElementClickInterceptedException: Message: Element <a id="ctl00_ContentPlaceHolder1_CompanyDetail1_lnkNewsTab" href="#divNews"> is not clickable at point (307,786) because another element <iframe id="webpush-onsite" name="webpush-onsite"> obscures it
here is some part of code I tried tough
driver = webdriver.Firefox(executable_path=GeckoDriverManager().install())
stocks_data = ["AKPL","NICA"]
for stock_data in stocks_data:
self.driver.get(f'https://merolagani.com/CompanyDetail.aspx?symbol=
{stock_data.lower()}')
self.driver.find_element_by_xpath("//li[#id='navNews']"
"//a[#id='ctl00_ContentPlaceHolder1_CompanyDetail1_lnkNewsTab']").click()
If you really need to click it regardless a normal user won't be able because as the error says, there's an IFrame on top of it...
Try the following:
Set the window size to 1920x1080 or so, maybe the elements overlap because the screen on Selenium's session is too small 🤷‍♂️
Worst case scenario, inject some Javascript code to do it forcefully:
self.driver.execute_script("document.getElementById('ctl00_ContentPlaceHolder1_CompanyDetail1_lnkNewsTab').click()")
Click on exact coordinate (x,y) if you know it ofcs.

Selenium find an element and check if it's interactable [duplicate]

This question already has answers here:
ElementNotVisibleException: Message: element not interactable error while trying to click a button through Selenium and Python
(2 answers)
ElementNotVisibleException: Message: element not interactable in Robot Framework
(4 answers)
selenium.common.exceptions.ElementNotVisibleException: Message: element not interactable using Selenium
(1 answer)
'ElementNotVisibleException:element not interactable' error locating Google Search button even though element was waited for on Google Home Page
(3 answers)
Closed 2 years ago.
This is my code:
label = browser.find_elements_by_xpath('//label[contains(.,"{}")]'.format("XYZ"))
if label:
check if we can click this element (label[0]) if it's not clickable, continue.
Is it possible to find an element and then check if it's clickable?.
Normally this issue happened with webpages where when click button something else appeared. This means that element exists BUT you can't interact with him. How to handle this error or ignore and continue?
P.S. Similar question already asked several times, BUT I can't see the answer which will fit my needs. Solutions like implicitly_wait(1) and e.t.c. are not what I'm looking for.
I have used .is_displayed() which solved my issue.
Find element x
x[0].is_displayed()
if True carry on

selenium.common.exceptions.ElementClickInterceptedException: Message: element click intercepted: Element is not clickable at point [duplicate]

This question already has answers here:
Element MyElement is not clickable at point (x, y)... Other element would receive the click
(5 answers)
Closed 3 years ago.
in this case, I use the argument (--headless) of chrome webdriver, the error message will happened
my code is
chrome_options.add_argument('--headless')
if I give up the 'headless' option, the chrome will starup , and everting is going well, no error, and could continue running all the time
and every time, the error will happen at this code, it is a loop running function, totally 17 time, but will happen at the 4th time.
WebDriverWait(driver,10).until(EC.element_to_be_clickable((By.XPATH,'_tmp_'))).click()
without headless, everything is working perfectly, with headless, always stuck here, cannot understand why
You can perform JavaScriptExecutor click on the element as it directly performs the action on the div and is not affected by the position of the element on the page or the headless option.
You can do it like:
button = driver.find_element_by_xpath("_tmp_")
driver.execute_script("arguments[0].click();", button)

Element is not clickable at point because another element <span> obscures it [duplicate]

This question already has answers here:
Element MyElement is not clickable at point (x, y)... Other element would receive the click
(5 answers)
Closed 3 years ago.
I solved this issue with the following code, I didn't find a solution in other posts so I tried to make myself and worked just fine. I don't now if it's a good code because I'm new in Python and programming but it worked.
As I wanted to select the element using visible text (not by value or option number), I used the following code, which consist in finding the element by Xpath [contains(text(), 'text')] and then changing the html. Maybe it's useful for another one.
self.driver.execute_script(
"arguments[0].selected=true",
self.driver.find_element_by_xpath(
'//*[contains(text(), "%s" )]' % 'your_visible_text'
),
)
this issue usually occurs in chrome browser as chrome uses point location. this happens when element is loaded in DOM but postion not fixed on UI. There can be certains solutions you could use to fix this:
Wait:
Use of WebDriverwait and Expected Conditions classes.
Eg:
visiblityOfElementLocated(By locator)
or
visibilityOf(WebElement element)
we are waiting for element to be present and visible before performing action
try to maximise the browser window before selecting dropdown
driver .manage().window().maximize();
Hope this help. Code is using Java selenium please use its corresponding Python code.

ElementClickInterceptedException: element click intercepted: [duplicate]

This question already has answers here:
Element MyElement is not clickable at point (x, y)... Other element would receive the click
(5 answers)
Closed 3 years ago.
I'm trying to submit one form on wordpress plugin using selenium + python. When I press publish button , it is giving an error.
ElementClickInterceptedException: element click intercepted: Element
type="submit" name="publish" id="publish" class="button button-primary button-large" value="Publish"> is not clickable at point (728, 15). Other element would receive the click:
...
I have tried following solutions:
Used action driver, but it didn't work.
Used webdriverwait() function, it didn't work.
Used Xpath, CSS selector, ID - It's giving same error in all three.
` browser.find_element_by_css_selector("""#save-post""").click()
WebDriverWait(driver, 90).until(EC.element_to_be_clickable((By.ID, "save-post"))).click()
`
Note that when I run that specific line in python console, it is working. But while running the full script, it is showing error.
There are so many similar questions on portal but none of them worked. Kindly help me to solve this issue.
Ok, the answer is in error message - "Other element would receive the click: ..."
I had the same problem when I just started using selenium.
Couldn't figure out what's the problem. "Other element would receive the click: ..." means there is other element above(overlapping) your element(pop up window, page is grayed out or disabled while loading, Some JS running etc., so when Selenium trying to click on your element its actually clicking on that blocking element.
Selenium is running really fast and clicking before its become clickable, that's why u are not able to click on it - "when I run that specific line in python console, it is working" Try to click after time.sleep() 5-10 sec or run script with debug mode.
If this is the case then you can use wait or add condition before find your element to check that element that prevent from clicking on you element is not there then u click on your element.

Categories