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:
JavaScript
x
2
1
<li class="limarginSP"><a class="spLink ng-binding" href="" ng-click="utility.ngPostForm(trans)">Finance System</a></li>
2
I tried this :
JavaScript
1
11
11
1
from selenium import webdriver
2
import time
3
4
driver = webdriver.Ie(executable_path="IEDriverServer.exe")
5
#local web site
6
driver.get("http://path.net")
7
t = 5
8
time.sleep(t)
9
elem_pyFinSys= driver.find_element_by_link_text("Finance System")
10
elem_pyFinSys.click()
11
but this will open another link in my page
inspection of the link opened below
JavaScript
1
2
1
<a class="navLink ng-binding" href="" ng-click="utility.ngPostForm(supp)">Reporting Subscription</a>
2
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:
JavaScript
1
2
1
driver.find_element_by_css_selector("limarginSP>.spLink.ng-binding")
2
Or
JavaScript
1
2
1
driver.find_element_by_css_selector(".limarginSP")
2
find_element_by_link_text
is not always a good idea because there may be many same locators.