Does anybody have idea how they would automate opening and closing links on Github page of your project? So basically I wanted to automate opening and closing all the links on my Github page just to make sure none of the links are broken. Idea is it would open a link one by one (there are hundreds of links) and if the link is opened successfully it would close it and go to the next one if the link is broken it would print that link is broken and would continue to the next one.
I tried to do this in Selenium but for some reason Selenium was giving me a error that element is not interactable. I tried to find solution online but I did not have any luck. So I decided to try here maybe someone has any solution or something I would be thankful
driver.get("https://github.com/project")
links = driver.find_elements_by_xpath('//*[#href]')
for link in links:
link.click()
Here is the error:
File "d:\Python\test.py", line 15, in <module>
link.click()
File "C:\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Python39\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Python39\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Python39\lib\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
I didn't even get to the part where I would close the tab and print error since I am failing on first step
Related
I am trying to click on an element that should send me to the next page, however, I can't seem to properly locate it or even locate any item on the page.
HTML Code for Element
<a data-qa="menu-button"
class="HeaderMenu__HeaderItemButton-kr6p0e-0 hbeYmr MenuButton__MenuButtonWrapper-dq0g44-0 imLDTG"
data-cv-test="headerSearchLink"
href="/cars"
target="_self">Search Cars
</a>
Visual of what I'm trying to click on
My code that does not work (I have the proper import statements)
PATH = "my_path_to_chromedriver"
driver = webdriver.Chrome(PATH)
driver.get("https://www.carvana.com")
link = driver.find_element_by_class_name('HeaderMenu__HeaderItemButton-kr6p0e-0 hbeYmr MenuButton__MenuButtonWrapper-dq0g44-0 imLDTG')
link.click()
I have tried searching by class name using this approach and just get this error message
link = driver.find_element_by_class_name('HeaderMenu__HeaderItemButton-kr6p0e-0 hbeYmr MenuButton__MenuButtonWrapper-dq0g44-0 imLDTG')
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/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 "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 976, in find_element
return self.execute(Command.FIND_ELEMENT, {
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/site-packages/selenium/webdriver/remote/webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.9/lib/python3.9/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":".HeaderMenu__HeaderItemButton-kr6p0e-0 hbeYmr MenuButton__MenuButtonWrapper-dq0g44-0 imLDTG"}
(Session info: chrome=xx.x.xxxx.xxx)
I have also tried searching by CSS selector. I even did a little sanity check and searched for the very first line of html code on the website and for some reason it gave me the same error. Anything helps... thank you!
The problem is you have spaces in the class name. The class name function doesn't work for that, I would suggest trying
driver.find_element_by_css_selector('.HeaderMenu__HeaderItemButton-kr6p0e-0.hbeYmr.MenuButton__MenuButtonWrapper-dq0g44-0.imLDTG')
driver.find_element_by_class_name('HeaderMenu__HeaderItemButton-kr6p0e-0
hbeYmr MenuButton__MenuButtonWrapper-dq0g44-0 imLDTG')
This code give return a node list and u can't click it , you may try get the first element , so here is the code :
driver.find_element_by_class_name('HeaderMenu__HeaderItemButton-kr6p0e-0
hbeYmr MenuButton__MenuButtonWrapper-dq0g44-0 imLDTG')[0]
Or bye doing this in the console of the navigator with js like this :
document.getElementByNames('HeaderMenu__HeaderItemButton-kr6p0e-0
hbeYmr MenuButton__MenuButtonWrapper-dq0g44-0 imLDTG')[0]
I'm trying to create a content scraper to gather a list of medical terms and I'm using https://www.merriam-webster.com/browse/medical for that task. All I have in my code right now is:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Firefox()
driver.get("https://www.merriam-webster.com/browse/medical/a")
driver.close()
The following error message is shown after every run of the program using this or any https://www.merriam-webster.com URL:
Traceback (most recent call last):
File "mw-download.py", line 5, in <module>
driver.get("https://www.merriam-webster.com/browse/medical/a")
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 268, in get
self.execute(Command.GET, {'url': url})
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 256, in execute
self.error_handler.check_response(response)
File "/usr/local/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: Reached error page: about:neterror?e=dnsNotFound&u=https%3A//nop.xpanama.net/if.html%3Fadflag%3D1%26cb%3DKHg6C73w9F&c=UTF-8&f=regular&d=Firefox%20can%E2%80%99t%20find%20the%20server%20at%20nop.xpanama.net.
I have tried changing the URL to different sites, with and without https support to test if it was something with https, but I haven't encountered this error with any other site. I also tried removing the driver.close() command at the end of the script to see if trying to close the driver before the page contents were loaded is what was causing the problem but the problem persists even without that line of code.
Any help in understanding this error and fixing it would be greatly appreciated!
I am attempting to click a button on a html page using Python and selenium web driver.
This is the source code of the page http://pastebin.com/112g1Gje.
EDIT: The relevant part at is at the end.. "btn btn-primary"
I am really close to figuring this out:
The class name had spaces in it and I replaced the spaces with the dots... that made it work (Thanks to another SO post).
driver.find_element_by_css_selector(".btn.btn-primary").click()
Now the error I get is:
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
So I am trying something like:
driver.execute_script('document.querySelector("btn.btn-primary").click()')
From my understanding I have to write a javascript that clicks the button instead because the element is not visible. But that doesn't work.
The error I get is almost unreadable:
driver.execute_script('document.querySelector("btn.btn-primary").click()')
File "/Users/Richie/anaconda/lib/python3.5/site- packages/selenium/webdriver/remote/webdriver.py", line 461, in execute_script
{'script': script, 'args':converted_args})['value']
File "/Users/Richie/anaconda/lib/python3.5/site- packages/selenium/webdriver/remote/webdriver.py", line 233, in execute
self.error_handler.check_response(response)
File "/Users/Richie/anaconda/lib/python3.5/site- packages/selenium/webdriver/remote/errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.WebDriverException: Message: document.querySelector(...) is null
Anyone know?
driver.find_element_by_css_selector(".btn.btn-lg.btn-block.btn-message.open-write-message").click()
I was clicking the wrong thing.
Make sure to include the dots.
I am trying to save the page as entire html using selenium, page has a dropdown list in it. There are 2 elements in that list and I want to save the entire html after clicking each of them.
Below is the code I am using:
devlink='http://www.t-mobile.com/content/tmo-wem/en/index/cell-phones/nokia-lumia-521.html'
devname= devlink[devlink.rfind("/")+1:]
ignore_tags=('script','noscript','style')
with contextlib.closing(webdriver.Firefox()) as browser:
browser.get(devlink) # Load page
dropdown = browser.find_element_by_class_name('dropdown-menu')
elements = dropdown.find_elements_by_tag_name('li')
i=0
for element in elements:
element.click()
i = i+1
time.sleep(2)
content=browser.page_source
cleaner=clean.Cleaner()
content=cleaner.clean_html(content)
with open(str(i)+devname,'w') as f:
f.write(content.encode('utf-8'))
This code is giving me a error, traceback of which looks like this Traceback (most recent call last):
File "D:\Windows Phone\Pricing\August\2013-08-05\tmo test\tmo_us_selenium.py", line 52, in <module>
element.click()
File "C:\Python27\lib\site-packages\selenium-2.33.0-py2.7.egg\selenium\webdriver\remote\webelement.py", line 54, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Python27\lib\site-packages\selenium-2.33.0-py2.7.egg\selenium\webdriver\remote\webelement.py", line 228, in _execute
return self._parent.execute(command, params)
File "C:\Python27\lib\site-packages\selenium-2.33.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 165, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium-2.33.0-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 158, in check_response
raise exception_class(message, screen, stacktrace)
ElementNotVisibleException: Message: u'Element is not currently visible and so may not be interacted with' ; Stacktrace:
at fxdriver.preconditions.visible (file:///c:/users/abhina~1.tal/appdata/local/temp/tmpwnu8em/extensions/fxdriver#googlecode.com/components/command_processor.js:7736)
at DelayedCommand.prototype.checkPreconditions_ (file:///c:/users/abhina~1.tal/appdata/local/temp/tmpwnu8em/extensions/fxdriver#googlecode.com/components/command_processor.js:10437)
at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/abhina~1.tal/appdata/local/temp/tmpwnu8em/extensions/fxdriver#googlecode.com/components/command_processor.js:10456)
at DelayedCommand.prototype.executeInternal_ (file:///c:/users/abhina~1.tal/appdata/local/temp/tmpwnu8em/extensions/fxdriver#googlecode.com/components/command_processor.js:10461)
at DelayedCommand.prototype.execute/< (file:///c:/users/abhina~1.tal/appdata/local/temp/tmpwnu8em/extensions/fxdriver#googlecode.com/components/command_processor.js:10401)
This code is not able to click the 2 elements it is finding, please help me in resolving this issue.
Selenium 2.33 supports Firefox 21 and older. You will have to wait for the Selenium update to have it support FF 22.
Refer to this thread for further details. There are many threads on google that discuss similar issues with Selenium 2.33 and FF 22
New to python and Selenium and programming for that matter.
I am trying to automate selenium to hit a specific link. In this case, I want it to hit the link associated with the link text "B":
<li>B
on this website:
http://www.lw.com
I am using this code:
def get_single_link_using_find_elements_by_link_name(url, link_name):
driver = webdriver.Firefox()
driver.get(url)
driver.implicitly_wait(10)
time.sleep(20)
element = driver.find_element_by_link_text(link_name)
element.click()
I added some wait conditions, because I thought the problem might have been a rendering problem, but they didnt help.
I am getting the following error:
Traceback (most recent call last):
File "C:\Python27\programs\selenium commands.py", line 50, in <module>
get_single_link_using_find_elements_by_link_name(url, link_name)
File "C:\Python27\programs\selenium commands.py", line 47, in get_single_link_using_find_elements_by_link_name
element = driver.find_element_by_link_text(link_name)
File "C:\Python27\lib\site-packages\selenium-2.25.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 237, in find_element_by_link_text
return self.find_element(by=By.LINK_TEXT, value=link_text)
File "C:\Python27\lib\site-packages\selenium-2.25.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 671, in find_element
{'using': by, 'value': value})['value']
File "C:\Python27\lib\site-packages\selenium-2.25.0-py2.7.egg\selenium\webdriver\remote\webdriver.py", line 156, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium-2.25.0-py2.7.egg\selenium\webdriver\remote\errorhandler.py", line 147, in check_response
raise exception_class(message, screen, stacktrace)
NoSuchElementException: Message: u'Unable to locate element: {"method":"link text","selector":"B"}'
Oddly enough, the same code WORKS on the following url, which is part of the same site:
http://www.lw.com/people?searchIndex=A
Any ideas?
Your code works for me, when I pass it a page that has the alphabetic listing index. This means that you're passing the wrong variables to the function-- the page that you're passing in, doesn't have a link named 'B', plain and simple.
You can check whether or not the alphabetic thing is on the page by calling driver.find_element_by_id("IndexControl1"). IndexControl1 is the name of the id in which the alphabetic thing is contained.
alphabet = driver.find_element_by_id("IndexControl1")
link_b = alphabet.find_element_by_link_text("B")
Incidentally, something else to watch out for is that if you're already on the page with "B" selected, e.g. http://www.lw.com/people?searchIndex=B&esmode=1, the letter B does not show up as a link and you will end up with a NoSuchElementException in this case, as well.
I think that covers pretty much every case where NoSuchElementException could pop up. Good luck.