0

I am an accountant and very novice coder. I am trying to use Selenium with Python and Firefox browser to click through a series of webpages. I am just trying to select and click a hyperlink on the page, but I can't seem to locate it with Selenium. Please can someone show me the simplest way to select the hyperlink I want?

Imports:

from selenium import webdriver
from selenium.webdriver.common.by import By
import time

I then have code which successfully nagivates to a webpage, inputs my username and password and submits the form. Then when I want to click a link on the next page:

time.sleep(5) # to make sure webpage loads before trying to find link
Link1 = browser.find_element(By.partialLinkText ("/maf/app/auth")); # or any easier selector method?
Link1.click()

The error message is "AttributeError: type object 'By' has no attribute 'partialLinkText'"

When I inspect the link element it looks like this - not sure what the easiest element is to locate and subsequently click it?

<a target="_blank" title="Go to Orbitax" href="/maf/app/authentication/sso/ping/redirect?target=orbitax_chre">
Go to Orbitax 
<img src="/cpw/images/rightBlueArrow.png" alt=">" 
width="5" height="8"></a>

Thanks in advance!

2 Answers2

1

Your code snippet here

time.sleep(5) # to make sure webpage loads before trying to find link
Link1 = browser.find_element(By.partialLinkText ("/maf/app/auth")); # or any easier selector method?
Link1.click()

There is no By.partialLinkText in the Selenium Python bindings. It should be

    time.sleep(5) # to make sure webpage loads before trying to find link
    Link1 = browser.find_element(By.PARTIAL_LINK_TEXT, "/maf/app/auth"); # or any easier selector method?
    Link1.click()
demouser123
  • 4,108
  • 9
  • 50
  • 82
0

Either you are using old version of selenium or import is not work correctly.

Try to update the selenium to the latest version.

OR

use the below code if you are using an old version of chrome.

time.sleep(5)
link1 = browser.find_element(By.LINK_TEXT, "Go to Orbitax")
link1.click()
Akzy
  • 1,817
  • 1
  • 7
  • 19