baransjd
baransjd

Reputation: 21

Click font awesome button python & selenium

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>

Upvotes: 0

Views: 1607

Answers (2)

cruisepandey
cruisepandey

Reputation: 29382

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

Upvotes: 1

Ishita Shah
Ishita Shah

Reputation: 4035

You may refer this,

Its class, Not ID.

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

Upvotes: 0

Related Questions