Oct-18-2020, 10:51 AM
i am playing around learning how selenium is supposed to work , i think that this is a really cool module.
but i am struggling with web elements a little bit. when it comes to links.. i do not under stand why when i copy the css path , the css selector or even the xpath what i paste into the idle isnt working.. i obviously have misunderstood something about element selectors (at least when it comes to links.), i can find the search bar of google , duckduckgo and bing but when i try the links to the web sites nada.., if some one could help out. this is the last thing i was messing with just a simple open webpage but i cant even get the link to work.
i guess i should also add that i am using firefox.
but i am struggling with web elements a little bit. when it comes to links.. i do not under stand why when i copy the css path , the css selector or even the xpath what i paste into the idle isnt working.. i obviously have misunderstood something about element selectors (at least when it comes to links.), i can find the search bar of google , duckduckgo and bing but when i try the links to the web sites nada.., if some one could help out. this is the last thing i was messing with just a simple open webpage but i cant even get the link to work.
i guess i should also add that i am using firefox.
import pyautogui from selenium import webdriver import time browser = webdriver.Firefox() browser.get('https://www.duckduckgo.com') search_bar = browser.find_element_by_css_selector('#search_form_input_homepage') search_bar.click() search_bar.send_keys('liveleak') search_bar.submit() LL = browser.find_element_by_css_selector("#r1-0 > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > a:nth-child(2) > span:nth-child(1) ") LL.click() time.sleep(5) browser.close()and i have also tried a try and except line..
from selenium import webdriver import time browser = webdriver.Firefox() browser.get('https://www.duckduckgo.com') search_bar = browser.find_element_by_css_selector('#search_form_input_homepage') search_bar.click() search_bar.send_keys('liveleak') search_bar.submit() try: LL = browser.find_element_by_css_selector("#r1-0 > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > a:nth-child(2) ") LL.click() except: ll = browser.find_element_by_css_selector("#r1-0 > div:nth-child(1) > div:nth-child(2) > div:nth-child(1) > a:nth-child(2) > span:nth-child(1)") ll.click() finally: print('neither of those worked') time.sleep(5) browser.close()