简体   繁体   English

Python,硒find_element_by_link_text不起作用

[英]Python, selenium find_element_by_link_text not working

I am trying to scrape a website. 我正在尝试抓取一个网站。 Where in I have to press a link. 我必须在哪里按下链接。 for this purpose, I am using selenium library with chrome drive. 为此,我在chrome驱动器中使用了硒库。

from selenium import webdriver

url = 'https://sjobs.brassring.com/TGnewUI/Search/Home/Home?partnerid=25222&siteid=5011&noback=1&fromSM=true#Applications'
browser = webdriver.Chrome()
browser.get(url)
time.sleep(3)

link = browser.find_element_by_link_text("Don't have an account yet?")
link.click()

But it is not working. 但这是行不通的。 Any ideas why it is not working? 任何想法为什么它不起作用? Is there a workaround? 有解决方法吗?

You can get it done in several ways. 您可以通过几种方式来完成它。 Here is one of such. 这就是其中之一。 I've used driver.execute_script() command to force the clicking. 我已经使用driver.execute_script()命令来强制单击。 You should not go for hardcoded delay as they are very inconsistent. 您不应该进行硬编码的延迟,因为它们非常不一致。

Modified script: 修改后的脚本:

from selenium import webdriver
from selenium.webdriver.common.by import By
from selenium.webdriver.support.ui import WebDriverWait as wait
from selenium.webdriver.support import expected_conditions as EC

url = 'https://sjobs.brassring.com/TGnewUI/Search/Home/Home?partnerid=25222&siteid=5011&noback=1&fromSM=true#Applications'

driver = webdriver.Chrome()
driver.get(url)

item = wait(driver, 10).until(EC.presence_of_element_located((By.CSS_SELECTOR, "a[ng-click='newAccntScreen()']")))
driver.execute_script("arguments[0].click();",item)

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

相关问题 Python Selenium find_element_by_link_text 对我不起作用 - Python Selenium find_element_by_link_text not working for me 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' 'WebDriver' 对象没有属性 'find_element_by_link_text' - 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