Skip to content
Advertisement

Selenium webdriver : find element question

I am trying to use python Selenium for the first time.
This would be a simple question for some of you but I am a bit disappointed here..

I would click on a link text which will open another webpage (WebDriver IE)

When I inspect the link I have this:

<li class="limarginSP"><a class="spLink ng-binding" href="" ng-click="utility.ngPostForm(trans)">Finance System</a></li>

I tried this :

from selenium import webdriver
import time

driver = webdriver.Ie(executable_path="IEDriverServer.exe")
#local web site
driver.get("http://path.net") 
t = 5
time.sleep(t)
elem_pyFinSys= driver.find_element_by_link_text("Finance System")
elem_pyFinSys.click()

but this will open another link in my page
inspection of the link opened below

<a class="navLink ng-binding" href="" ng-click="utility.ngPostForm(supp)">Reporting Subscription</a>

My question is how to get the right element to open the right page? I have to use Internet explorer as the application won’t work with other browser.

Thanks in advance

Advertisement

Answer

Try to use one of the following locators:

driver.find_element_by_css_selector("limarginSP>.spLink.ng-binding")

Or

driver.find_element_by_css_selector(".limarginSP")

find_element_by_link_text is not always a good idea because there may be many same locators.

User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement