Python Forum
Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
selenium & weblinks help
#1
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.


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()
Reply


Messages In This Thread
selenium & weblinks help - by gr3yali3n - Oct-18-2020, 10:51 AM
RE: selenium & weblinks help - by snippsat - Oct-18-2020, 01:04 PM
RE: selenium & weblinks help - by gr3yali3n - Oct-18-2020, 03:23 PM
RE: selenium & weblinks help - by gr3yali3n - Oct-21-2020, 05:50 AM
RE: selenium & weblinks help - by snippsat - Oct-21-2020, 08:15 AM
RE: selenium & weblinks help - by gr3yali3n - Nov-05-2020, 05:12 AM

Possibly Related Threads…
Thread Author Replies Views Last Post
  Error in Selenium: CRITICAL:root:Selenium module is not installed...Exiting program. AcszE 1 3,687 Nov-03-2017, 08:41 PM
Last Post: metulburr

Forum Jump:

User Panel Messages

Announcements
Announcement #1 8/1/2020
Announcement #2 8/2/2020
Announcement #3 8/6/2020