I want to download the pdf file uploaded to Linkedin using Selenium. So I need to click on this full screen box and then I need to click on download.
But I am getting error NoSuchElementException when I am using the following code:
driver.find_element_by_class_name("artdeco-icon").click()
Please Help how to click on that full screen rectangular box.
Check the full error below :
---------------------------------------------------------------------------
NoSuchElementException Traceback (most recent call last)
<ipython-input-46-b333460fb62c> in <module>
4 # driver.execute_script("window.scrollTo(0, document.body.scrollHeight);")
5 # sleep_rand(4)
----> 6 driver.find_element_by_class_name("artdeco-icon").click()
7 # WebElement svgObject = driver.findElement(By.xpath());
8
~\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in find_element_by_class_name(self, name)
752 stacklevel=2,
753 )
--> 754 return self.find_element(by=By.CLASS_NAME, value=name)
755
756 def find_elements_by_class_name(self, name) -> WebElement:
~\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in find_element(self, by, value)
1236 value = '[name="%s"]' % value
1237
-> 1238 return self.execute(Command.FIND_ELEMENT, {
1239 'using': by,
1240 'value': value})['value']
~\anaconda3\lib\site-packages\selenium\webdriver\remote\webdriver.py in execute(self, driver_command, params)
416 response = self.command_executor.execute(driver_command, params)
417 if response:
--> 418 self.error_handler.check_response(response)
419 response['value'] = self._unwrap_value(
420 response.get('value', None))
~\anaconda3\lib\site-packages\selenium\webdriver\remote\errorhandler.py in check_response(self, response)
241 alert_text = value['alert'].get('text')
242 raise exception_class(message, screen, stacktrace, alert_text) # type: ignore[call-arg] # mypy is not smart enough here
--> 243 raise exception_class(message, screen, stacktrace)
244
245 def _value_or_default(self, obj: Mapping[_KT, _VT], key: _KT, default: _VT) -> _VT:
NoSuchElementException: Message: no such element: Unable to locate element: {"method":"css selector","selector":".artdeco-icon"}
(Session info: chrome=100.0.4896.60)
Stacktrace:
Backtrace:
Ordinal0 [0x00A67413 2389011]
Ordinal0 [0x009F9F61 1941345]
Ordinal0 [0x008EC658 837208]
Ordinal0 [0x009191DD 1020381]
Ordinal0 [0x0091949B 1021083]
Ordinal0 [0x00946032 1204274]
Ordinal0 [0x00934194 1130900]
Ordinal0 [0x00944302 1196802]
Ordinal0 [0x00933F66 1130342]
Ordinal0 [0x0090E546 976198]
Ordinal0 [0x0090F456 980054]
GetHandleVerifier [0x00C19632 1727522]
GetHandleVerifier [0x00CCBA4D 2457661]
GetHandleVerifier [0x00AFEB81 569713]
GetHandleVerifier [0x00AFDD76 566118]
Ordinal0 [0x00A00B2B 1968939]
Ordinal0 [0x00A05988 1989000]
Ordinal0 [0x00A05A75 1989237]
Ordinal0 [0x00A0ECB1 2026673]
BaseThreadInitThunk [0x750D6739 25]
RtlGetFullPathName_UEx [0x76F08E7F 1215]
RtlGetFullPathName_UEx [0x76F08E4D 1165]
CodePudding user response:
I noticed that your selector is misspelled. Maybe try correcting that first, and if it still does not work try the code below.
from selenium.webdriver.common.by import By
driver.find_element_by_css_selector(".artdeco-icon").click()
Please make sure that the CSS selector that you use is unique and ready to be selected by the time it gets executed by adding some wait time. You can do it explicitly by importing the time
library.
import time
time.sleep(3)
driver.find_element_by_css_selector(".artdeco-icon").click()
CodePudding user response:
You can use below and check the WebDriverWait Here explained very well.
WebDriverWait(driver,20).until(EC.visibility_of_all_elements_located((by_css_selector, ".artdeco-icon"))).click()