I wrote an Instagram bot with Python and Selenium, which works just fine. Most of the time.
Sometimes, in save data when it should click "don't save," its randomly throws this error:
WebDriverException: browsingContextFn() .currentWindowGlobal is null
When I restart the program, it just works fine.
My question is: what does this error mean and how can I fix it? I tried to search this but found nothing.
I can post my code if really needed but I'm not that good at coding and it's a little messy.
Related
I am writing my script to automate the form filling process for multiple websites.
So I basically targeted all fields using the xpath input type = xxx
But the strange thing is that the half-done script was perfect when running. it didnt show any errors. After a few days, I decided to run the script again to continue my work but the script shows an error now.
textfields = web.find_elements_by_xpath('//input[#type="text"]')
for textfield in textfields:
if textfield.get_attribute('value')!=Name:
textfield.click()
textfield.send_keys(Name)
The variable Name contains a string message of my name. So when the script is run, the error comes from the textfield.click() saying element not interactable. The strange thing is, when I use a VPN from VPNBook, this error does not show up. But the only issue when using the VPN is that I cannot submit the form as it detects me as spam as my IP is from other country.
I would like to know what is causing this error. Am i doing something wrong?
Note: I am using Kali Linux and Python.
I'm wondering why the code works sometimes and sometimes not. My IDE gives me this debugging error:
Message: no such element: Unable to locate element:
{"method":"xpath","selector":"/html/body/div[4]/div/div/div[2]"}
(Session info: chrome=90.0.4430.93)
def find_followers(self):
self.driver.get(URL+ACCOUNT)
follow = self.driver.find_element_by_xpath('/html/body/div[1]/section/main/div/header/section/ul/li[3]/a')
follow.click()
time.sleep(10)
modal = self.driver.find_element_by_xpath('/html/body/div[6]/div/div/div[2]')
for i in range(10):
self.driver.execute_script('arguments[0].scrollTop = arguments[0].scrollHeight', modal)
time.sleep(13)
I'm trying to make a script which goes to Instagram and opening up a Instagram accounts followers. The script goes well till this error. I've checked the XPath and it is surely right. I tried the script for a few days and it was working, but now when I tried again it dosen't. I'm new with Python and want to learn why this happen and how to solve it.
You need to close the cookie popup and login to instagram in order to see the followers list. I'd recommend creating a second function called "initiate_instagram" that does that.
You could also login manually, because of 2 factor authentication.
Cant submit Captcha textfield in python selenium
Hello everyone,
I want to submit a textfield which is filled with the Code for Captcha, but I can't submit it.
This is the Error:
Exception has occurred: NoSuchElementException
Message: Unable to locate element: ./ancestor-or-self::form
enter image description here
This is my script(it works perfectly on other webpages):
sub = driver.find_element_by_class_name("g-recaptcha-response")
sub.submit()
have tried also a lot of other things, but nothing worked.
Here the HTML-Code:
enter image description here
The Textfield is that in the whole bottom.
I would be very happy, if someone can help me. Thank you for you time!
Ps: This is my first Question, so sorry, if I did something wrong. And I am not from the USA or England, so my English is a bit bad...
The reason this error occurs is that you are trying to find a specific element before it is rendered.
To put it simply, the web page is not ready yet, but it is a problem that occurs when you try to scrape information.
sub = driver.find_element_by_class_name("g-recaptcha-response")
sub.submit()
Edit it!
From official Selenium documentation:
CAPTCHA, short for Completely Automated Public Turing test to tell Computers and Humans Apart, is explicitly designed to prevent automation, so do not try!
What you could do instead is
Disable CAPTCHAs in your test environment
Add a hook to allow tests to bypass the CAPTCHA
I've just started using Selenium and I can successfully fill a form and click the submit button using the examples code, however I get an error message (which only appears written in the website after submitting, not an actual coding error) which says "There has been an error, try again".
It seems to me the website somehow knows I'm not filling the form manually, and it doesn't like that.
Is that the case ? What can I do in such cases ?
EDIT: This is the website with the form I'm trying to submit:
https://www.alitalia.com/it_it/special-pages/richiesta-rimborso-volo-cancellato.html
I searched for a solution to my problem but couldnt find any.
Is there a way to open a URL in python and get the console output from that url?
Im trying to check a list of URLs for Javascript errors.
The only solution I found was using Selenium but its incredible slow.
For chrome errors you might find the node module of LightHouse suiting your needs.
For Firefox there is Browser_Console.
From first look the Chrome solution seems easier.
Last but not least I stumbled over the python module selenium which can do liveserver testing.
For reference see this django use case, there is also an other post how to catch js errors