[英]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.