I think my question is somehow related to this post
Selenium - cannot click on an element inside a modal
I click on a an element and it opens a modal table. Then, I would like to select a particular checknox in a long list but Selenium gives me back an error.
That's what I did:
I tested first with Selenium IDE: first I recorded the operations but when I try to replay them in the log I get this:
Running 'Step2_sele'
1.open on /reserve-space/... OK
2.click on css=a[title="Locations"] > span... OK
3.click on linkText=Add/Remove Locations... OK
4.Trying to find xpath=//input[#value='2427']... Failed:
Element is not currently visible and may not be manipulated
I thought I should have given more time to the element to show up and I wrote this with Python
browser = webdriver.Chrome()
browser.get(url_res)
time.sleep(10)
browser.find_element_by_css_selector('a[title="Locations"]>span').click()
time.sleep(10)
browser.find_element_by_css_selector('a.dynamic-filter-item-add.summary').click()
time.sleep(10)
browser.find_element_by_xpath("xpath=//input[#value='2427']").click()
But I get this other error
Traceback (most recent call last):
File "bot.py", line 69, in <module>
browser.find_element_by_xpath("xpath=//input[#value='2427']").click()
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 393, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 966, in find_element
'value': value})['value']
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.InvalidSelectorException: Message: invalid selector: Unable to locate an element with the xpath expression xpath=//input[#value='2427'] because of the following error:
TypeError: Failed to execute 'evaluate' on 'Document': The result is not a node set, and therefore cannot be converted to the desired type.
(Session info: chrome=69.0.3497.100)
(Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.16299 x86_64)
This is a screenshot of how the html code look like because I cannot post the real url
I assume the xpath string causes the problem. If my assumption is correction, the following should work:
browser.find_element_by_xpath("//input[#value='2427']").click()
Related
I am trying to send some keystrokes using python webdriver to a p element that is attached to a js event listener. When i type the keys in manually, it works. However when I use driver.send_keys(), it returns an ElementNotInteractableException. The element is as follows:
<p data-v-6779462c="" id="textBox" class="input"></p>
My code to locate and send the keystrokes to the element is as follows:
input_area = WebDriverWait(driver, 10).until(EC.presence_of_element_located((By.XPATH, '//p[#id="textBox"]')))
input_area.click()
input_area.send_keys(keys)
input_area.send_keys(Keys.ENTER)
The full stacktrace is as follows:
Traceback (most recent call last):
File "automation.py", line 32, in <module>
input_area.send_keys(word)
File "/home/server/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 477, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT,
File "/home/server/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "/home/server/.local/lib/python3.8/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/home/server/.local/lib/python3.8/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotInteractableException: Message: element not interactable
(Session info: chrome=87.0.4280.66)
I am using Chrome on Ubuntu Linux.
I need the way to solve this and why it is happening.
Thanks in advance!
P tag is a paragraph tag , you cannot Interact with it .
You should be sending keys to input tag
Try below code
input_area.click()
elemInput = driver.switch_to.active_element
elemInput.send_keys(Keys.ENTER)
I am new in programming (specifically Python Selenium), I have a question regarding pasting a data into an input box, it seems not working if I will paste data on another website, I will received an error. But if I use just one website (either of the two) in pasting the data it is working fine.
Here is my codes below.
from selenium import webdriver
driver = webdriver.Chrome(executable_path=r'C:\Users\Pashu\AppData\Local\Programs\Python\Python37\chromedriver.exe')
driver.get('https://tinyurl.com/')
inline_tinysite = driver.find_element_by_xpath('//*[#id="url"]')
inline_tinysite.send_keys("https://www.teamxtools.com/content/images/project-7/stack-324/exif/2dehands-velgen-volkswagen-golf-7.jpg")
submit = driver.find_element_by_xpath('/html/body/div[2]/div[2]/div[2]/div[2]/div[2]/form/input[3]')
submit.click()
driver.execute_script("window.open('https://cutt.ly/', 'new window')")
inline_cuttly = driver.find_element_by_xpath('//*[#id="link"]')
inline_cuttly.send_keys("https://www.teamxtools.com/content/images/project-7/stack-324/exif/2dehands-velgen-volkswagen-golf-7.jpg")
submit2 = driver.find_element_by_xpath('/html/body/div[1]/section[1]/div/div/div/div/div/button')
submit2.click()
#time.sleep(8)
Here is the error message as text:
C:\Users\Pashu\PycharmProjects\untitled\venv\Scripts\python.exe C:/Users/Pashu/AppData/Roaming/JetBrains/PyCharmCE2020.1/scratches/Helloworld.py
Traceback (most recent call last):
File "C:/Users/Pashu/AppData/Roaming/JetBrains/PyCharmCE2020.1/scratches/Helloworld.py", line 14, in <module>
inline_cuttly = driver.find_element_by_xpath('//*[#id="link"]')
File "C:\Users\Pashu\PycharmProjects\untitled\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 394, in find_element_by_xpath
return self.find_element(by=By.XPATH, value=xpath)
File "C:\Users\Pashu\PycharmProjects\untitled\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
'value': value})['value']
File "C:\Users\Pashu\PycharmProjects\untitled\venv\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\Pashu\PycharmProjects\untitled\venv\lib\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":"xpath","selector":"//*[#id="link"]"}
(Session info: chrome=81.0.4044.138)
Process finished with exit code 1
it was stuck on window 1, that is why element //*[#id="link"] is not found. I just added
driver.switch_to.window(driver.window_handles[1])
for it to search on the second window.
Attempting to run a code found from this github project
I keep running into the following errors:
DevTools listening on ws://127.0.0.1:12522/devtools/browser/17d610a1-0dc4-45da-8766-b1592dd689ab
Logging into Linkedin account ...
Traceback (most recent call last):
File ".\LinkedinEasyApply.py", line 244, in <module>
login(driver, username, password)
File ".\LinkedinEasyApply.py", line 49, in login
driver.get("https://www.linkedin.com/")
File "C:\Users\Seane\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 332, in get
self.execute(Command.GET, {'url': url})
File "C:\Users\Seane\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "C:\Users\Seane\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: cannot determine loading status
from unknown error: missing or invalid 'entry.level'
(Session info: chrome=68.0.3440.106)
(Driver info: chromedriver=2.29.461591 (62ebf098771772160f391d75e589dc567915b233),platform=Windows NT 10.0.17134 x86_64)
I am using windows 64.. I'm not sure if Selenium can't find the path or what the issue is. Currently, the program opens Linkedin before the error occurs. I've tried numerous different solutions inlcuding different versions of chrome, and different paths to Selenium and Chrome.
If I use Chrome version 2.41 (the latest) I get this message...
Traceback (most recent call last):
File ".\LinkedinEasyApply.py", line 246, in <module>
searchJobs(driver)
File ".\LinkedinEasyApply.py", line 92, in searchJobs
search_button.click()
File "C:\Users\Seane\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Users\Seane\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webelement.py", line 628, in _execute
return self._parent.execute(command, params)
File "C:\Users\Seane\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 320, in execute
self.error_handler.check_response(response)
File "C:\Users\Seane\AppData\Local\Programs\Python\Python36\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: unknown error: Element <button class="jobs-search-box__submit-button button-secondary-large-inverse" data-ember-action="" data-ember-action-1764="1764">...</button> is not clickable at point (971, 20). Other element would receive the click: <a id="ember1706" data-control-name="premium_nav_upsell_text_click" title="Free Upgrade to Premium" href="/premium/products/?destRedirectURL=https%3A%2F%2Fwww.linkedin.com%2Fjobs%2F%3FshowPremiumWelcomeBanner%3Dtrue&upsellOrderOrigin=premium_nav_upsell_text" class="link-without-visited-state nav-item__spotlight-upsell premium-upsell-link--long ember-view">...</a>
(Session info: chrome=68.0.3440.106)
(Driver info: chromedriver=2.41.578737 (49da6702b16031c40d63e5618de03a32ff6c197e),platform=Windows NT 10.0.17134 x86_64)
Thanks! & Let me know if I can be of any help.
Update
- You are trying to click an element that is not visible or clicking on another span because of an overlay over the button, given the error here -
Other element would receive the click: <a id="ember1706" data-control-name="premium_nav_upsell_text_click" title="Free Upgrade to Premium" href="/premium/products/?destRedirectURL=https%3A%2F%2Fwww.linkedin.com%2Fjobs%2F%3FshowPremiumWelcomeBanner%3Dtrue&upsellOrderOrigin=premium_nav_upsell_text" class="link-without-visited-state nav-item__spotlight-upsell premium-upsell-link--long ember-view">...</a>
Original Answer
Update your chrome driver (currently 2.29) from here to latest version 2.41 -
https://sites.google.com/a/chromium.org/chromedriver/downloads
Your current driver doesn't supports the Chrome version i.e. ver 68
I'm webscraping a lot of webpages. Sometimes an alert box shows. I get past these alert boxes using
browser.switch_to.alert.accept()
But after I pass a lot of pages, a captcha box shows up. As I'm passing the alert box with switch_to.alert.accept, the code also gets past the captcha box too, when it appears (without validate it).
I am not able to stop when this captcha appears. I want to end the running of the code when the captcha appears, to prevent myself being block by the site.
How to pass the boxes and stop on captchas (and get ride of the error below)?
The following algorithm works when i comment the sentence. That piece of code below is a tentative to find the captcha in the page.
print 'FIND ELEMENT?:'+browser.find_elements_by_xpath("//div[#class='phm _1yw']")
Algorithm:
for index, element in enumerate(result):
browser.get(WEBSITEa_URL+element)
try:
send= browser.find_elements_by_xpath("//div[#class='notranslate _5rpu']")[0]
send.send_keys(config.message+Keys.ENTER)
except Exception as f:
time.sleep(2)
print 'FIND ELEMENT?:'+browser.find_elements_by_xpath("//div[#class='phm _1yw']")
print 'AAA'
browser.switch_to.alert.accept()
message that shows up on prompt:
ENVIOU MENSAGEM PARA 100002557631967 5
Traceback (most recent call last):
print 'ACHOU?:'+browser.find_elements_by_xpath("//div[#class='phm _1yw']")
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 344, in find_element_by_id
return self.find_element(by=By.ID, value=id_)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 858, in find_element
'value': value})['value']
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 311, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 237, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.UnexpectedAlertPresentException: Alert Text: None
Message: unexpected alert open: {Alert text : }
(Session info: chrome=68.0.3440.106)
(Driver info: chromedriver=2.36.540470 (e522d04694c7ebea4ba8821272dbef4f9b818c91),platform=Windows NT 6.3.9600 x86_64)
I use Python Beautiful Soup to move through DOM elements and Selenium to open page in chrome and ActionChains to scroll in page. It worked fine but the website changed something and now I run into two kinds of error on the way it worked before and on a new way as a possible solution.
Old solution:
submit_button = driver.find_element_by_name('quantity')
elementList = submit_button.find_elements_by_tag_name("option")
elementList[int(column)-1].click()
Old Error:
Traceback (most recent call last):
File "C:/Users/Felix_P/PycharmProjects/Price_Tool/Combination_14_6_2016.py", line 205, in <module>
elementList[int(column)-1].click()
File "C:\Python35-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 75, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Python35-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 469, in _execute
return self._parent.execute(command, params)
File "C:\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 201, in execute
self.error_handler.check_response(response)
File "C:\Python35-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 193, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: element not visible: Element is not currently visible and may not be manipulated
(Session info: chrome=51.0.2704.103)
(Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 SP1 x86_64)
New Solution:
submit_button = driver.find_element_by_name('quantity')
elementList = submit_button.find_elements_by_tag_name("option")
actions.move_to_element(elementList[int(column)-1]).click().perform()
New Error:
Traceback (most recent call last):
File "C:/Users/Felix_P/PycharmProjects/Price_Tool/Combination_14_6_2016.py", line 201, in <module>
actions.move_to_element(elementList[int(column)-1]).click().perform()
File "C:\Python35-32\lib\site-packages\selenium\webdriver\common\action_chains.py", line 72, in perform
action()
File "C:\Python35-32\lib\site-packages\selenium\webdriver\common\action_chains.py", line 217, in <lambda>
self._driver.execute(Command.MOVE_TO, {'element': to_element.id}))
File "C:\Python35-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 201, in execute
self.error_handler.check_response(response)
File "C:\Python35-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 193, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
(Session info: chrome=51.0.2704.103)
(Driver info: chromedriver=2.21.371459 (36d3d07f660ff2bc1bf28a75d1cdabed0983e7c4),platform=Windows NT 6.1 SP1 x86_64)
From you error stack, it shows that your reserved reference were stale. This usually is caused by page refresh or enven a page event.
So you have to get the element again before access it.
For example,
elements = driver.find_elements_by_tag_name('tagname'))
for element in elements:
driver.get(element.get_attribute('url'))
will cause
selenium.common.exceptions.StaleElementReferenceException
I think I see the problem. If you show all of your code, it will probably show that last line is within a for loop that is navigating away from the page, then coming back to the same page (or some ajax has refreshed that set of options on the page). The problem is that the page has reloaded, so the target element from elementList doesn't exist any longer.
You'll need to define your elementList by keeping track of a list of something like value on the option, then use find_element within the loop to find each unique option element again.