I'm very new at this so apologies if this is a silly question. I am trying to use Selenium to automate a form filling process. I have managed to automate the login details on URL 1. URL 1 then redirects me to URL 2 where I'm supposed to input data that will then redirect me to URL 3. The problem I'm facing is that the find elements command for the second URL does not seem to be working.
HTML code for URL 2 is as follows:
input name="ctl00$ContentPlaceHolder1$txtNofNo" type="text" id="ctl00_ContentPlaceHolder1_txtNofNo" class="standardtextbox"
`
code I've tried so far
I've edited this code based on suggestions:
wait = WebDriverWait(driver, 20)
time.sleep(10)
newURl = driver.window_handles[0]
driver.switch_to.window(newURl)
driver.find_element_by_xpath("//*[contains(#id,'NofNo')]").sendKeys("Selenium");
And I'm now getting the following error messages.
Traceback (most recent call last):
newURl = driver.window_handles[0] File "C:\Users\kg3517\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 724, in window_handles
return self.execute(Command.W3C_GET_WINDOW_HANDLES)['value'] File
"C:\Users\kg3517\Anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py",
line 321, in execute
self.error_handler.check_response(response) File "C:\Users\kg3517\Anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py",
line 242, in check_response
raise exception_class(message, screen, stacktrace) WebDriverException: chrome not reachable (Session info:
chrome=90.0.4430.212)
I suspect the problem mainly arises because of the change in URL but am not sure how to fix it.
Related
I am learning Pythons so please bear with me.
I adopted LinkedIn-Easy-Apply-Bot from: https://github.com/voidbydefault/LinkedIn-Easy-Apply-Bot
While the bot is working perfectly fine on my test account but when I change the email ID/password to real account (with everything being the same), I start getting these errors:
Traceback (most recent call last):
File "/home/me/Documents/LinkedIn-Easy-Apply-Bot/linkedineasyapply.py", line 124, in apply_jobs
job_results = self.browser.find_element_by_class_name("jobs-search-results")
File "/home/me/PycharmProjects/Better-LinkedIn-EasyApply-Bot/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 766, in find_element_by_class_name
return self.find_element(by=By.CLASS_NAME, value=name)
File "/home/me/PycharmProjects/Better-LinkedIn-EasyApply-Bot/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 1251, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "/home/me/PycharmProjects/Better-LinkedIn-EasyApply-Bot/venv/lib/python3.10/site-packages/selenium/webdriver/remote/webdriver.py", line 430, in execute
self.error_handler.check_response(response)
File "/home/me/PycharmProjects/Better-LinkedIn-EasyApply-Bot/venv/lib/python3.10/site-packages/selenium/webdriver/remote/errorhandler.py", line 247, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".jobs-search-results"}
(Session info: chrome=102.0.5005.61)
I have tried deleting chromedriver to ensure version conflicts do not exit, I have tried adding time.sleep(5) in line 124 (above) and also tried driver.implicitly_wait(10). Unfortunately, the error persists with my real account.
Note that there are no issues with my real account if used manually. I am able to apply all sorts of jobs whether EasyApply or otherwise and the bot is working 100% fine on my test account hence the elements the code is looking for exist.
Please help in fixing the problem.
Thanks.
since several days, i can not connect to google drive in google colaboratory.
here is the code, that before always worked:
from google.colab import drive
drive.mount('/content/gdrive/')
I tried the following, after reading several blogs for a solution:
-> I only have two items in my first folder of google drive
-> My trash folder is empty
-> I reset all the sessions
-> I create new file for testing just the piece of code above.
-> I restarted my computer and my browser Chrome
-> I tried "drive.mount('/content/gdrive')" , drive.mount('/content/gdrive/'), drive.mount('/content/'), drive.mount('/content'), drive.mount('/content/gdrive/My Drive')
Any idea?
Thanks a lot!
here is the error:
TIMEOUT Traceback (most recent call last)
<ipython-input-2-9a9a89271754> in <module>()
1 from google.colab import drive
----> 2 drive.mount('/content/gdrive/')
4 frames
/usr/local/lib/python3.6/dist-packages/pexpect/expect.py in timeout(self, err)
142 exc = TIMEOUT(msg)
143 exc.__cause__ = None # in Python 3.x we can use "raise exc from None"
--> 144 raise exc
145
146 def errored(self):
TIMEOUT: <pexpect.popen_spawn.PopenSpawn object at 0x7f5666fe0a90>
searcher: searcher_re:
0: re.compile('google.colab.drive MOUNTED')
1: re.compile('root#2cd8a6fe3c15-de18aaee18634b4c829aedf956090476: ')
2: re.compile('(Go to this URL in a browser: https://.*)$')
3: re.compile('Drive File Stream encountered a problem and has stopped')
4: re.compile('drive EXITED')
<pexpect.popen_spawn.PopenSpawn object at 0x7f5666fe0a90>
searcher: searcher_re:
0: re.compile('google.colab.drive MOUNTED')
1: re.compile('root#2cd8a6fe3c15-de18aaee18634b4c829aedf956090476: ')
2: re.compile('(Go to this URL in a browser: https://.*)$')
3: re.compile('Drive File Stream encountered a problem and has stopped')
4: re.compile('drive EXITED')
This is being tracked in https://github.com/googlecolab/colabtools/issues/1540.
Workaround is to copy the oauth code using a mouse-drag instead of using the "copy" button.
It looks like someone suggested manually copy-pasting the authentication code generated instead of pressing the copy button and then pasting. This worked for me :)
Hi i copied the authentication code on to notepad and then pasted it from there onto the colab. It worked.
I am trying to scrape LinkedIn website using selenium and Beautiful Soup.
The idea is simple, I started in the company's LinkedIn website then go to company search and scroll to the bottom of the page to get all results on the page.
But because Linkedin just provides 10 people per page so I need to find the next button on that page to go to the next 10 people.
I use this code
browser.find_element_by_class_name('next')
Traceback (most recent call last): File "LinkedInWebcrawler2019.py",
line 71, in
nextt = browser.find_element_by_class_name('next') File "C:\Users\Afdal\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webdriver.py",
line 564, in find_element_by_class_name
return self.find_element(by=By.CLASS_NAME, value=name) File "C:\Users\Afdal\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webdriver.py",
line 978, in find_element
'value': value})['value'] File "C:\Users\Afdal\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\webdriver.py",
line 321, in execute
self.error_handler.check_response(response) File "C:\Users\Afdal\AppData\Roaming\Python\Python37\site-packages\selenium\webdriver\remote\errorhandler.py",
line 242, in check_response
raise exception_class(message, screen, stacktrace) selenium.common.exceptions.NoSuchElementException: Message: no such
element: Unable to locate element: {"method":"css
selector","selector":".next"} (Session info: chrome=77.0.3865.75)
Any ideas?
Try this for finding the next button.
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
Next =WebDriverWait(driver, 10).until(EC.element_to_be_clickable(By.XPATH,'//*[contains(#class,'button')'))
Next.click()
How does the webrtc pipeline get any information about its peers?
This is what I assume what the on_negotiation_needed callback does?
def start_pipeline(self):
self.pipe = Gst.parse_launch(PIPELINE_DESC)
self.webrtc = self.pipe.get_by_name('sendrecv')
**self.webrtc.connect('on-negotiation-needed', self.on_negotiation_needed)**
self.webrtc.connect('on-ice-candidate', self.send_ice_candidate_message)
self.webrtc.connect('pad-added', self.on_incoming_stream)
self.pipe.set_state(Gst.State.PLAYING)
I see that it has the on_negotiation_needed callback but its unclear where the element variable comes from? I looked here: http://blog.nirbheek.in/2018/02/gstreamer-webrtc.html and here: https://github.com/centricular/gstwebrtc-demos and I am still confused as to how this negotiation works? From what I understand there are 2 (or more) peers and both of them must connect to the signaling server, then one of them has to create an offer.
I await for the message from (I assume) the gstreamer webrtcbin on the signaling server:
print (websocket.remote_address)
#get message from client
message = await asyncio.wait_for(websocket.recv(), 3000)
and I get this error when the pipline starts:
('192.168.11.138', 44120)
Error in connection handler
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/websockets/protocol.py", line 674, in transfer_data
message = yield from self.read_message()
File "/usr/local/lib/python3.6/dist-packages/websockets/protocol.py", line 742, in read_message
frame = yield from self.read_data_frame(max_size=self.max_size)
File "/usr/local/lib/python3.6/dist-packages/websockets/protocol.py", line 815, in read_data_frame
frame = yield from self.read_frame(max_size)
File "/usr/local/lib/python3.6/dist-packages/websockets/protocol.py", line 884, in read_frame
extensions=self.extensions,
File "/usr/local/lib/python3.6/dist-packages/websockets/framing.py", line 99, in read
data = yield from reader(2)
File "/usr/lib/python3.6/asyncio/streams.py", line 672, in readexactly
raise IncompleteReadError(incomplete, n)
asyncio.streams.IncompleteReadError: 0 bytes read on a total of 2 expected bytes
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/lib/python3.6/dist-packages/websockets/server.py", line 169, in handler
yield from self.ws_handler(self, path)
File "signaling_server.py", line 34, in signaling
message = await asyncio.wait_for(websocket.recv(), 3000)
File "/usr/lib/python3.6/asyncio/tasks.py", line 358, in wait_for
return fut.result()
File "/usr/local/lib/python3.6/dist-packages/websockets/protocol.py", line 434, in recv
yield from self.ensure_open()
File "/usr/local/lib/python3.6/dist-packages/websockets/protocol.py", line 646, in ensure_open
) from self.transfer_data_exc
websockets.exceptions.ConnectionClosed: WebSocket connection is closed: code = 1006 (connection closed abnormally [internal]), no reason
I cannot say about Python (unfortunately, cannot make Python bindings for GStreamer work on Windows), however, demo works from C# (I just checked).
First you should connect with your browser to https://webrtc.nirbheek.in/, and get the 'Our id' value.
Your Python Gstreamer should connect to wss://webrtc.nirbheek.in:8443, and use the Id value from the browser.
The browser will get the test image stream from the GStreamer, and the GStreamer application will get the Webcam image from the browser.
HTH, Tom
Here's a screenshot:
I am currently experimenting with Behavioral Driven Development. I am using behave_django with selenium. I get the following output
Creating test database for alias 'default'...
Feature: Open website and print title # features/first_selenium.feature:1
Scenario: Open website # features/first_selenium.feature:2
Given I open seleniumframework website # features/steps/first_selenium.py:2 0.001s
Traceback (most recent call last):
File "/home/vagrant/newproject3/newproject3/venv/local/lib/python2.7/site-packages/behave/model.py", line 1456, in run
match.run(runner.context)
File "/home/vagrant/newproject3/newproject3/venv/local/lib/python2.7/site-packages/behave/model.py", line 1903, in run
self.func(context, *args, **kwargs)
File "features/steps/first_selenium.py", line 4, in step_impl
context.browser.get("http://www.seleniumframework.com")
File "/home/vagrant/newproject3/newproject3/venv/local/lib/python2.7/site-packages/behave/runner.py", line 214, in __getattr__
raise AttributeError(msg)
AttributeError: 'Context' object has no attribute 'browser'
Then I print the title # None
Failing scenarios:
features/first_selenium.feature:2 Open website
0 features passed, 1 failed, 0 skipped
0 scenarios passed, 1 failed, 0 skipped
0 steps passed, 1 failed, 1 skipped, 0 undefined
Took 0m0.001s
Destroying test database for alias 'default'...
Here is the code:
first_selenium.feature
Feature: Open website and print title
Scenario: Open website
Given I open seleniumframework website
Then I print the title
first_selenium.py
from behave import *
#given('I open seleniumframework website')
def step_impl(context):
context.browser.get("http://www.seleniumframework.com")
#then('I print the title')
def step_impl(context):
title = context.browser.title
assert "Selenium" in title
manage.py
#!/home/vagrant/newproject3/newproject3/venv/bin/python
import os
import sys
sys.path.append("/home/vagrant/newproject3/newproject3/site/v2/features")
import dotenv
if __name__ == "__main__":
path = os.path.realpath(os.path.dirname(__file__))
dotenv.load_dotenv(os.path.join(path, '.env'))
from configurations.management import execute_from_command_line
#from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)
I'm not sure what this error means
I know it is a late answer but maybe somebody is going to profit from it:
you need to declare the context.browser (in a before_all/before_scenario/before_feature hook definition or just test method definition) before you use it, e.g.:
context.browser = webdriver.Chrome()
Please note that the hooks must be defined in a separate environment.py module
In my case the browser wasn't installed. That can be a case too. Also ensure path to geckodriver is exposed if you are working with Firefox.