0

I am trying to run Python / Selenium script that clicks a font awesome button on a static HTML website.

I've tried several ID names but I keep getting exceptions.

When I right click and 'inspect element' the ID tag is what I have enetered currently.

I don't want to use xpath.

Any help would be greatly appreciated, thanks.

Python script:

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
import time
import unittest

driver = webdriver.Chrome()
driver.get("http://www.baransjd.com")
time.sleep(2)
driver.find_element_by_id("i.fa.fa-linkedin-square.fa-2x")
click()
time.sleep(2)
driver.close()

HTML for the font awesome button (no CSS)

<a target="_blank" href="https://www.linkedin.com/in/dan-b-33b89b158/"> <i class="fa fa-linkedin-square fa-2x" style="color:#5B5B5B"></i></a>
2
  • 1
    "i.fa.fa-linkedin-square.fa-2x" is a CSS selector. So, using find_element_by_id won't work. Use find_element_by_css_selector instead. driver.find_element_by_css_selector("i.fa.fa-linkedin-square.fa-2x").click(). Commented Jul 16, 2018 at 5:25
  • Hi Keyur, this solved my problem. Thank you so much. Commented Jul 16, 2018 at 16:12

2 Answers 2

1

You can try this code:

use css selector (There is no ID associated with the respective element). you can't use id here in your case to find your desired element.

driver.get("http://www.baransjd.com/")
linkdin= driver.find_element_by_css_selector("div.container i[class*='linkedin-square']")
linkdin.click()
Sign up to request clarification or add additional context in comments.

1 Comment

Did you try the code provided by me ? It worked at my end though. More over I have provided css selector as per your requirement which is more stable as compared to keyur css selector
0

You may refer this,

Its class, Not ID.

driver.find_element_by_xpath("//i[@class='fa fa-linkedin-square fa-2x']").click()

1 Comment

Appreciate the response, but I am trying to avoid using x-path in this scenario.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.