0
<a href="/?redirectURL=%2F&amp;returnURL=https%3A%2F%2Fpartner.yanolja.com%2Fauth%2Flogin&amp;serviceType=PC" aria-current="page" class="v-btn--active v-btn v-btn--block v-btn--depressed v-btn--router theme--light v-size--large primary" data-v-db891762="" data-v-3d48c340=""><span class="v-btn__content">
    login
  </span></a>

I want to click this href button using python-selenium.

First, I tried to using find_element_by_xpath(). But, I saw a error message that is no such element: Unable to locate element. Then, I used link_text, partial_link_text, and so on.

I think that message said that 'It can't find login-button' right? How can I specify the login button?

It is my first time to using selenium, and My html knowledge is also not enough. What should I study first?

+)

url : https://account.yanolja.bz/

I want to login and get login session this URL.

from urllib.request import urlopen
from bs4 import BeautifulSoup
from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.support import expected_conditions as EC

html = urlopen('https://account.yanolja.bz/')
id = 'ID'
password = 'PW'

#options = webdriver.ChromeOptions()
#options.add_argument("headless")
#options.add_argument("window-size=1920x1080")
#options.add_argument("--log-level=3")

driver = webdriver.Chrome("c:\\chromedriver")
driver.implicitly_wait(3)
driver.get('https://account.yanolja.bz/')

print("Title: %s\nLogin URL: %s" %(driver.title, driver.current_url))
id_elem = driver.find_element_by_name("id")
id_elem.clear()
id_elem.send_keys(id)

driver.find_element_by_name("password").clear()
driver.find_element_by_name("password").send_keys(password)
2
  • First check the page for any iframes. Commented Sep 30, 2020 at 4:48
  • you should give more details, i.e the web url, full html of the page or even your source code to show exactly what you have been done. Commented Sep 30, 2020 at 5:14

2 Answers 2

1

Most probably this thing is not working due to span in your a tag. I have tried to give some examples but I am not sure, if you are supposed to click the a tag or span. I have tried to click the span in all of them.
I hope it does work. Only if you could give us what you have tried, it would be a great help to find out mistakes, if any.

Have you tried to find the element using class. Your link is named by so many classes, Is none of them unique?
driver.find_element(By.CLASS_NAME, "{class-name}").click()

using x-path:
driver.find_element_by_xpath("//span[@class='v-btn__content']").click() driver.find_element_by_xpath("//a[@class='{class-name}']/span[@class='v-btn__content']").click()

if this xpath is not unique then you can use css selector
driver.find_element_by_css_selector("a[aria-current='page']>span.v-btn__content").click()

Sign up to request clarification or add additional context in comments.

2 Comments

Thanks a lot! driver.find_element_by_xpath("//span[@class='v-btn__content']").click() This code works! Thank you! However, In your answer 'Most probably this thing is not working due to span in your a tag.' means that span tag blocks a tag?? Does this often happen?
This thing has also happened to me a few times due to child tag under the a tag. You have to click the child tag rather than 'a' tag. So this might not let find_by_link_text work.<br> And I am just guessing this, there might be another reason.
1

Firstly, I want to note that span class="v-btn__content">login</span> is not clickable. Thus, it raises an error.

Try to use this instead

driver.find_element_by_xpath('//a[@href="'+url+'"]')

Replace url with the url given in <a href='url'>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.