I want to delete youtube's watch later videos. but my codes don't work.
<button class="yt-uix-button yt-uix-button-size-default yt-uix-button-default yt-uix-button-empty yt-uix-button-has-icon no-icon-markup pl-video-edit-remove yt-uix-tooltip" type="button" onclick=";return false;" title="Remove"></button>
my code is this.
_sDriver.get('https://www.youtube.com/playlist?list=WL')
_sDriver.find_element_by_class_name('pl-video-edit-remove').click()
exception is this.
>>> _sDriver.find_element_by_class_name('pl-video-edit-remove')
<selenium.webdriver.remote.webelement.WebElement (session="283d423c-5ff7-478f-89
b9-002499413126", element="{e00dbb1e-e0ca-4f79-8652-23c955b464e7}")>
>>> _sDriver.find_element_by_class_name('pl-video-edit-remove').click()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 72, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webelement.py",
line 461, in _execute
return self._parent.execute(command, params)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\webdriver.py", l
ine 236, in execute
self.error_handler.check_response(response)
File "C:\Python27\lib\site-packages\selenium\webdriver\remote\errorhandler.py"
, line 192, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not c
urrently visible and so may not be interacted with
Stacktrace:
at fxdriver.preconditions.visible (file:///c:/users/admini~1/appdata/local/t
emp/tmppqz9zq/extensions/fxdriver#googlecode.com/components/command-processor.js
:10092)
at DelayedCommand.prototype.checkPreconditions_ (file:///c:/users/admini~1/a
ppdata/local/temp/tmppqz9zq/extensions/fxdriver#googlecode.com/components/comman
d-processor.js:12644)
at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/admini~1/ap
pdata/local/temp/tmppqz9zq/extensions/fxdriver#googlecode.com/components/command
-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///c:/users/admini~1/appd
ata/local/temp/tmppqz9zq/extensions/fxdriver#googlecode.com/components/command-p
rocessor.js:12666)
at DelayedCommand.prototype.execute/< (file:///c:/users/admini~1/appdata/loc
al/temp/tmppqz9zq/extensions/fxdriver#googlecode.com/components/command-processo
r.js:12608)
I don't know what can I do for this.
I need your help.
thank you.
The element that you are trying to click is not visible normally. It is only visible when you hover the mouse on it. So either you fire a mouseover event before clicking and try if it works.
The other solution is that you can try executing the JavaScript.
driver.execute_script("document.getElementsByClassName('pl-video-edit-remove')[0].click()")
The script is working at my end.
you may want to add some wait before executing the script so that the page loads properly.
Related
Okay so I was writing my first selenium code which is:
browser.get('https://www.jetbrains.com/pycharm/')
browser.find_element_by_link_text('Download')
<selenium.webdriver.remote.webelement.WebElement (session="69f43bf4a5e98baf24ad3746dd01b514", element="0fa96685-d871-464f-aaaa-af02238a5f08")>
I wanted to simply go to the pycharm website and click on downloads, which worked fine.
But when I tried to store the previous function in a variable like so:
elem = browser.find_element_by_link_text('Download')
I got all these errors:
Traceback (most recent call last):
File "<input>", line 1, in <module>
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 428, in find_element_by_link_text
return self.find_element(by=By.LINK_TEXT, value=link_text)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 978, in find_element
'value': value})['value']
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\admin\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 242, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.NoSuchWindowException: Message: no such window: window was already closed
(Session info: chrome=87.0.4280.66)
I have no idea what they mean or what ive done wrong. Help much appreciated.
PS: I am using pycharm and selenium chromedriver if thats helpful.
No issues in this.
from selenium import webdriver
browser = webdriver.Chrome(executable_path='C:/bin/chromedriver.exe')
browser.get('https://www.jetbrains.com/pycharm/')
element = browser.find_element_by_link_text('Download')
element.click()
Image of the code and what the button looks like
Im trying to click that add button but I cant find anything that says button when i inspect element
Here is my python code im trying to get work but not sure how to do it
buttonclick = driver.find_elements_by_class_name('add-vehicle-container')
buttonclick.click()
time.sleep(1)
Errors im getting
Traceback (most recent call last):
File "C:/Users/ttttt/iCloudDrive/Documents/GitHub/SeniorProject2019TBA/Selenium/AboutYouTesting.py", line 50, in <module>
buttonclick.click()
File "C:\Users\ttttt\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 80, in click
self._execute(Command.CLICK_ELEMENT)
File "C:\Users\ttttt\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webelement.py", line 633, in _execute
return self._parent.execute(command, params)
File "C:\Users\ttttt\AppData\Local\Programs\Python\Python37-32\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 321, in execute
self.error_handler.check_response(response)
File "C:\Users\ttttt\AppData\Local\Programs\Python\Python37-32\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 <div class="add-vehicle-container"> could not be scrolled into view
Run one of these commands in the developer console.
getEventListeners($("#SomeElement")[0]); //Javascript
$._data($("#SomeElement")[0], "events"); //JQuery
These will tell you if the events attached are indeed "click" events, or some other type of event.
If it is indeed a click event, you can try this:
driver.execute_script("$('.add-vehicle-container').click()");
If that does not work, or the events are not click events, then you can run this:
driver.execute_script("$('.add-vehicle-container').trigger('ATTACHED_EVENT_NAME_HERE')");
You can play around with these to see if they work by simply running them in the browser developer console before trying them in your python script.
I'm new to python coding. And I'm trying to play around with python and Selenium in chrome. And I have this code where I'm trying to move a webpage up and down. But it isn't working.
body_elem = browser.find_element_by_tag_name('body')
for __ in range(3):
body_elem.send_keys(Keys.END)
sleep(2)
body_elem.send_keys(Keys.HOME)
sleep(2)
All I get is this long error message:
Traceback (most recent call last):
File "selenium_test.py", line 34, in <module>
body_elem.send_keys(Keys.HOME)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 479, in send_keys
'value': keys_to_typing(value)})
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webelement.py", line 628, in _execute
return self._parent.execute(command, params)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/webdriver.py", line 312, in execute
self.error_handler.check_response(response)
File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/selenium/webdriver/remote/errorhandler.py", line 242, 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
Anybody got an idea of whats is wrong?
This is most likely because of the fact that the DOM tree or the body element signature itself changed after the first "down" move. One straightforward way to approach the problem would be to "re-find" the element constantly:
for _ in range(3):
browser.find_element_by_tag_name('body').send_keys(Keys.END)
sleep(2)
browser.find_element_by_tag_name('body').send_keys(Keys.HOME)
sleep(2)
The folowing is a snip of some crowdfire.com HTML code, where im trying to upload a file in the input class =...
<div id="ember1089" class="ember-view">
<div id="ember1090" class="action__addImage pointer ember-view tooltipstered">
<div data-ember-action="1091">
<img class="iconImg iconImg--camera" src="/publish/images/icon-camera-b432ac4c5b369d4616baf097b951d9b4.png"/>
<span>Add an image</span>
</div>
<input class="js-file-input action__fileInput" type="file" data-ember-action="1092"/>
</div>
Now below is what i have so far. I have created driver instance, the code before logs in the website without a problem and locates all other xpaths
image = driver.find_element_by_xpath('.//*[#id=\'ember1089\']/input')
time.sleep(2)
print 'found element'
image.send_keys('C:\Users\Brian\Desktop\Empire_fort\Bots\GetPICtures\Empire.jpg)
print 'uploading'
time.sleep(5)
the following is the error i get, and i really don't understand what is the problem,On the website there is an "add an image" link. if clicked it brings up window's explorer from where the user can select a file and upload it.
waiting
about toupload
found element
Traceback (most recent call last):
File "C:\Users\Brian\Desktop\Empire_fort\Bots\GetPICtures\nowupload.py", line 55, in <module>
image.send_keys(r'C:\Users\Brian\Desktop\Empire_fort\Bots\GetPICtures\Empire.jpg')
File "C:\Python2.7.11\lib\site-packages\selenium\webdriver\remote\webelement.py", line 321, in send_keys
self._execute(Command.SEND_KEYS_TO_ELEMENT, {'value': keys_to_typing(value)})
File "C:\Python2.7.11\lib\site-packages\selenium\webdriver\remote\webelement.py", line 456, in _execute
return self._parent.execute(command, params)
File "C:\Python2.7.11\lib\site-packages\selenium\webdriver\remote\webdriver.py", line 236, in execute
self.error_handler.check_response(response)
File "C:\Python2.7.11\lib\site-packages\selenium\webdriver\remote\errorhandler.py", line 194, in check_response
raise exception_class(message, screen, stacktrace)
selenium.common.exceptions.ElementNotVisibleException: Message: Element is not currently visible and so may not be interacted with
Stacktrace:
at fxdriver.preconditions.visible (file:///c:/users/brian/appdata/local/temp/tmpxjigan/extensions/fxdriver#googlecode.com/components/command-processor.js:10092)
at DelayedCommand.prototype.checkPreconditions_ (file:///c:/users/brian/appdata/local/temp/tmpxjigan/extensions/fxdriver#googlecode.com/components/command-processor.js:12644)
at DelayedCommand.prototype.executeInternal_/h (file:///c:/users/brian/appdata/local/temp/tmpxjigan/extensions/fxdriver#googlecode.com/components/command-processor.js:12661)
at DelayedCommand.prototype.executeInternal_ (file:///c:/users/brian/appdata/local/temp/tmpxjigan/extensions/fxdriver#googlecode.com/components/command-processor.js:12666)
at DelayedCommand.prototype.execute/< (file:///c:/users/brian/appdata/local/temp/tmpxjigan/extensions/fxdriver#googlecode.com/components/command-processor.js:12608)
Thanks!
Ps Update, It works with with a webdriver.Chrome() instance but not with Firefox or phantomjs
I suspect you need to make the input visible first:
image = driver.find_element_by_css_selector('#ember1089 input')
driver.execute_script("arguments[0].style.display = 'block';", image);
image.send_keys('C:\Users\Brian\Desktop\Empire_fort\Bots\GetPICtures\Empire.jpg')
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