AnswerBun.com

Selenium Python - click on a link inside <a herf

Stack Overflow Asked by hadi0815 on January 5, 2022

It is a very unique situation that I can’t get it to work out. after logging into the website I want my code go and click on one of the times in the left side menu bar which has below element:

            <hr>
            <span class="hide-on-toggle" style="color: #225515;margin-left:10px;">GO</span>
            <br>
            <li class="hide-on-toggle jizzzHidden">
                <a href="/JIZZZ" target="_blank">
                  <span class="fa-stack fa-lg">
                    <i><img src="/resource/153270/images/logo.png">
                    </i>
                  </span>JIZZZ
                </a>
            </li>
            <li class="hide-on-toggle">
                <a href="https://login.html?serviceIier" target="_blank">
                  <span class="fa-stack fa-lg">
                    <i class="fa fa-desack-1x "></i>
                  </span> joozz
                </a>
            </li>
           
          </ul>
        </div>
    </div>

So here is my code so far

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support import expected_conditions
from selenium.webdriver.support.select import Select
from selenium.webdriver import ActionChains


driver = webdriver.Chrome()
driver.get("https://Login")


username = driver.find_element_by_id("username")
username.clear()
username.send_keys("etggrgrw.")

password = driver.find_element_by_name("password")
password.clear()
password.send_keys("xxxx")


driver.find_element_by_name("login").click()

driver.find_element_by_xpath("//span[text()='JIZZZ']").click();

I get an error of :

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element: {"method":"xpath","selector":"//span[text()='JIZZZ']"}

I also tried

driver.find_element_by_XPath("//*[@id=menu]/li[9]/a").Click()

but got error of :

AttributeError: 'WebDriver' object has no attribute 'find_element_by_XPath'

I am lost and appreciate any help.

One Answer

driver.find_element_by_xpath("//span[contains(text(), 'JIZZZ')]").click()

Answered by Cameron Russell on January 5, 2022

Add your own answers!

Related Questions

How can I get different margins when appending divs in CSS?

4  Asked on February 4, 2021 by michaelstackquestion

     

Getting error while running merged jtl files

2  Asked on February 4, 2021 by ajij-shaikh

   

Why don’t need to use free() function in this case?

2  Asked on February 4, 2021 by akrilmokus

     

how to show data of databse in navigation bar on laravel 7

2  Asked on February 4, 2021 by fahad-munir

     

String formatting: optional section

1  Asked on February 3, 2021 by cerno

     

Multiple table to encode json and display

1  Asked on February 3, 2021 by j-wujeck

   

i need to remove duplicated comments from every post

1  Asked on February 3, 2021 by rabie_alkholi

         

Why is C is much slower as compared to Java?

1  Asked on February 3, 2021 by jaysmito-mukherjee

       

Server returned HTTP response code: 429 for URL JAVA Reddit JSON

2  Asked on February 3, 2021 by luke-prior

     

How to measure sequential memory read speed in C/C++

1  Asked on February 3, 2021 by sz-ppeter

 

Ask a Question

Get help from others!

© 2023 AnswerBun.com. All rights reserved. Sites we Love: PCI Database, UKBizDB, Menu Kuliner, Sharing RPP