Having difficulty in choosing the link by its link_text in Python using Selenium

I am a beginner in the world of automation and I'm currently working on automating a website that contains various links. Initially, I hardcoded the user name and password, and was able to select the link using Link_text successfully. However, when I attempted to retrieve the data from an Excel file for the credentials, the username and password fields were populated but I encountered an issue with selecting the link. Can anyone offer assistance with this problem?

Here is the code snippet:

    import XLutils
    from selenium import webdriver
    
    from selenium.webdriver.common.by import By
    from selenium.webdriver.common.keys import Keys
    
    driver = webdriver.Chrome(r'C:\Users\test\AppData\Local\Programs\chromedriver_win32\chromedriver.exe')
    
    driver.get("https://test.com")
    
    driver.maximize_window()
    
    path = r'C:\Users\test\Desktop\Reports Test.xlsx'
    
    rows = XLutils.getRowCount(path, 'Login')
    
    username = XLutils.readData(path, "Login", 2, 1)
    password = XLutils.readData(path, "Login", 2, 2)
    
    driver.find_element(By.ID, 'username').clear()
    driver.find_element(By.ID, 'username').send_keys(username)
    driver.find_element(By.ID, 'password').clear()
    driver.find_element(By.ID, 'password').send_keys(password)
    driver.find_element(By.XPATH, '/html/body/app-root/body/div/app-login/div\[2\]/div\[2\]/form/div\[4\]/button').click()
    
    driver.find_element(By.LINK_TEXT, 'Offer Activity').click()

HTML:

<a class="reportLink" href="null"> Offer Activity </a>

Answer â„–1

modification

driver.find_element(By.LINK_TEXT, 'Offer Activity').click()

transform to

driver.find_element(By.XPATH, "//a[contains(text(), 'Offer Activity')]").click()

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Selenium: Issue with pageLoadTimeout not being effective on websites with continuous redirects

I utilize Selenium to navigate through various websites and save their HTML markup. To increase efficiency, I've implemented a pageLoadTimeout to trigger an exception for sites that take too long to load: driver.manage().timeouts().pageLoadTimeout(2 ...

Steps for accessing the search input box in Office365 Hotmail:1. Open your web

I'm having trouble with automating the process of opening an email through searching for the email address. Despite trying various XPaths and Actions, I can't seem to click on the search box. Can anyone provide assistance? This is being done in ...

Python code to verify if a specific condition is satisfied within a certain time period

Seeking to determine if certain conditions are met over a period of time. The data is structured as follows: Datetime Valve1 Valve2 01/01/2020 11:00:01 1 0 The condition being evaluated is: (Valve1=1 for 1h) and (Valve-0 for 1h) Utilizing rolling ...

Ways to conceal *pyc files within the atom text editor

Recently delved into Python/Django development with the help of Atom, and now I'm looking to tidy up my sidebar by hiding all those pesky *.pyc files. Any tips on how to configure Atom to achieve this? ...

Having trouble accessing dynamically generated elements using Selenium

I've been attempting to change the router's SSIDs using a Selenium script, but I'm encountering difficulty accessing any JS elements generated by the router page. I've tried various Expected Conditions and methods without success. Here ...

Merge rows and complete missing values within each group

Below is the DataFrame that I am working with: X Y Z 0 xxx NaN 333 1 NaN yyy 444 2 xxx NaN 333 3 NaN yyy 444 I'm attempting to merge rows based on the values in the Z column, resulting in the following output: X ...

Python: Array of Arrays

As a Python beginner, I am currently working on a project that involves a List of lists. My goal is to display specific lists by searching for one of their elements. In this particular case, the List contains user information such as name, username, age, ...

Python 3: The list encounters a cycle of indices after passing index 47 with over 100 elements. What is the reason behind this behavior and how can it

Here's a function that calculates the nth prime number. I'm aware it's not the most efficient method, especially since I'm relatively new to coding. Despite this, the code below does work and will return the prime number at the specifie ...

Searching for the #document element using Python with Selenium WebDriver

While working with Python's Selenium Webdriver, I encountered a challenge when trying to access elements within an #document tag using the following HTML code. I attempted both driver.find_element_by_xpath("html/body/div[@id='frame']/ifram ...

Are you familiar with textbox interactions?

I have been utilizing Kantu to automate the process of completing various forms. One particular textbox is designed in such a way that when an individual's ID number is input and you click into another field or tab out of the box, it automatically loa ...

Extract information using Selenium from the script element

Currently, I am utilizing a script that enables the input of a chassis number and subsequently displays information related to the vehicle. In this process, my objective is to extract specific details including Marque et type, Dénomination commerciale, Va ...

Require verification to confirm if the latest document matches the one preceding it

Currently utilizing yolov5 for person detection. Below is the code snippet used to read files containing the count of people and display it: import os directory_path = r'C:\Users\MRTS\yolov5\runs\detect\ ...

Using Selenium and Java to manipulate dynamic web elements

Looking to use Selenium for interacting with an element on a website that dynamically changes content based on user behavior. The element in question always contains exactly one HTML element. In its default state, the element appears as follows: https:// ...

Experiencing difficulties with storing information in a ManyToMany field

My Model structure resembles this class Dish(models.Model): names = models.ManyToManyField(DishName) restaurant = models.ManyToManyField(Restaurant) Here is a snippet from my view file def AddDish(request): if request.method == 'POS ...

The radio button cannot be interacted with as Selenium cannot find any other unique identifier for it

While examining the code of the button, I landed on this specific section: <input type="radio" name="chosen" value="UniqueNameExample"> I am attempting to locate an element within this code that I can interact with by c ...

Learn how to effortlessly update models by integrating AngularJS with Django and Django Rest Framework

Here is a JSON representation of a post based on its ID: http://127.0.0.1:8000/update/1?format=json {"title": "about me", "content": "I like program", "created": "2014-11-29T18:07:18.173Z", "rating": 1, "id": 1} I am attempting to update the rating ...

Selenium with Python: Ensuring the Element's Text Change is Complete Before Retrieving its Value

I am having trouble obtaining the final value of a text from a webpage using Selenium in Python. The element appears and disappears rapidly, with the text value changing quickly until it settles on the ultimate result. It seems to involve some type of Java ...

Is it necessary to hover over the menu in order to access the clickable element?

Be sure to hover over the menu first before trying to click on the element! The element is currently not visible and cannot be interacted with (WARNING: The server did not provide any stacktrace information) error on Selenium I have attempted the followi ...

What methods does Ofbiz use to manage sessions?

Excuse my ignorance, but I am new to the world of web development. I am currently working on an application called OFBench which utilizes the Selenium library to mimic user browsing behavior on a website. The website is designed using the Ofbiz template w ...

Issue with Docker's depends_on flag not successfully handling dependencies between containers

My goal is to set up a Selenium hub, Chrome node, and Firefox node, and then run the test execution script in that specific order. I have the nodes depending on the hub, and the code depends on both the hubs. However, when I run docker-compose --build, it ...