我正在嘗試製作一個腳本,該腳本將大量應用於LinkedIn上的作業。它能夠成功登錄並搜索作業,收集包含特殊「linkedIn-apply」圖標的元素,這就是問題開始的地方。一旦它點擊其中一個,它會成功加載作業發佈的頁面,但在此之後它似乎無法找到任何東西。Selenium單擊鏈接並更新框架後無法找到任何內容
要添加更多信息,點擊工作發佈時,LinkedIn會自動在新標籤中打開發布。是否有可能驅動程序仍在主頁面上,並且看不到其他選項卡上的內容?
整個文件:
require 'selenium-webdriver'
require 'byebug'
caps = Selenium::WebDriver::Remote::Capabilities.chrome("chromeOptions" => {"excludeSwitches" => [ "--ignore-certificate-errors" ]})
driver = Selenium::WebDriver.for :chrome, :switches => %w[--test-type]
driver.navigate.to("https://www.linkedin.com/uas/login?goback=&trk=hb_signin")
# driver.switch_to.frame(0)
driver.find_element(:name, "session_key").send_keys("someuser")
driver.find_element(:name, "session_password").send_keys("somepassword")
driver.find_element(:name, "signin").click()
driver.switch_to.frame(0)
sleep 2
driver.find_element(:link_text, "Jobs").click()
sleep 2
e = driver.find_elements(:class, "in-apply-icon")
if e.empty?
driver.find_element(:class, "expand-button").click
else
e.each do |posting|
posting.click
sleep 10
driver.switch_to.frame(0)
sleep 10
# THIS is where it gets stuck. It cannot find the 'apply button'. I have tried
using :id and alas, no luck. I have tried finding other things and no luck.
driver.find_element(:class, "apply-button").click
sleep 5
driver.find_element(:id, "file-browse-input").send_keys(somepath)
sleep 5
driver.find_element(:id, "send-application-button").click
#find and click on apply
#upload resume
#submit
#hit x button/leave
#hit back button
end
end
向底部的代碼是不完整的,我是知道的。我甚至無法通過點擊應用按鈕,所以目前這不重要。
我猜你發現的元素,會過時或無法訪問,因爲一旦你申請一項工作,頁面可能會刷新。如果是這種情況,你需要在每次點擊後找到應用按鈕。是否拋出任何錯誤。請分享 – Siva
@Siva唯一的控制檯錯誤是指出沒有這樣的元素。 –