简体   繁体   English

Python Selenium find_element_by_link_text 对我不起作用

[英]Python Selenium find_element_by_link_text not working for me

I am trying to have Selenium log me into Soundcloud but the find_element_by_link_text attribute isn't working for me but it seems to work for "Find out more" and "Upload your own".我试图让 Selenium 将我登录到 Soundcloud,但 find_element_by_link_text 属性对我不起作用,但它似乎适用于“了解更多”和“上传您自己的”。 Why is it working for some of the elements on the web page but not others??为什么它适用于网页上的某些元素而不适用于其他元素?

from tkinter import *
import random
import urllib.request
from bs4 import BeautifulSoup
from selenium import webdriver
import time
import requests
from selenium.webdriver.support import expected_conditions as EC
from selenium.webdriver.common.by import By
from selenium.webdriver.common.keys import Keys
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.chrome.options import Options



driver = webdriver.Chrome(executable_path='/Users/quanahbennett/PycharmProjects/SeleniumTest/chromedriver')
url= "https://soundcloud.com/"
driver.get(url)
#time.sleep(30)

wait = WebDriverWait(driver, 10)
link = driver.find_element_by_link_text('Sign in');
link.click()


breakpoint()

The Element you are trying to find Sign in is not in a a tag to use driver.find_element_by_link_text .您尝试查找的元素Sign in不在用于使用driver.find_element_by_link_text a标签中。 Its in a button tag.它在一个button标签中。

Try like below and confirm:尝试如下并确认:

driver.get("https://soundcloud.com/")
wait = WebDriverWait(driver,30)

# Cookie pop-up
wait.until(EC.element_to_be_clickable((By.ID,"onetrust-accept-btn-handler"))).click()

# Click on Sign-in
wait.until(EC.element_to_be_clickable((By.XPATH,"//div[@class='frontHero__signin']//button[@title='Sign in']"))).click()

drakepolo,德雷克波罗

find_element_by_link_text()

function only work for text which are enclosed in anchor tag (sometimes they are called a tag).函数仅适用于包含在锚标记中的文本(有时称为标记)。

Below is the outerHTML for Upload your own下面是Upload your ownouterHTML

<a href="/upload" class="frontContent__uploadButton sc-button sc-button-cta sc-button-primary sc-button-large">Upload your own</a>

See here the text Upload your own is in enclosed in a tag in HTML.请参阅此处的文本“ Upload your own内容”包含在 HTML 标记中。

But for Sign In button :但是对于Sign In按钮:

<button type="button" class="g-opacity-transition frontHero__loginButton g-button-transparent-inverted sc-button sc-button-medium loginButton" tabindex="0" title="Sign in" aria-label="Sign in">Sign in</button>

it is wrapped inside in a button tag.它被包裹在一个按钮标签中。

So that is the reason find_element_by_link_text() will not work for Sign In button.所以这就是find_element_by_link_text()不适用于Sign In按钮的原因。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Python,硒find_element_by_link_text不起作用 - Python, selenium find_element_by_link_text not working python selenium find_element_by_link_text,元素存在但未找到 - python selenium find_element_by_link_text, element exists but not found Selenium RC python,使用find_element_by_link_text - selenium RC python, using find_element_by_link_text Python Selenium:find_element_by_link_text 不起作用 - Python Selenium: find_element_by_link_text doesn't work Selenium find_element_by_link_text无法用于完整网址 - Selenium find_element_by_link_text not working for full urls Selenium Python无法找到_element_by_link_text - Selenium Python unable to find_element_by_link_text Selenium - “站点”对象没有属性“find_element_by_link_text” - Selenium - 'site' object has no attribute 'find_element_by_link_text' &#39;WebDriver&#39; 对象没有属性 &#39;find_element_by_link_text&#39; - Selenium 脚本突然停止工作 - 'WebDriver' object has no attribute 'find_element_by_link_text' - Selenium script suddenly stopped working Selenium-Python-find_element_by_link_text不确定出什么问题 - Selenium - Python - find_element_by_link_text not sure what's wrong 如何在Python-Selenium中将朝鲜语作为自变量放在find_element_by_link_text()中? - How can I put Korean as an argument in find_element_by_link_text() in Python - Selenium?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM