簡體   English   中英

絕對路徑:Selenium Xpath 無法識別元素

[英]Absolute Path: Selenium Xpath Can't Identify Element

我正在嘗試使用 Xpath 識別 HTML 按鈕,並嘗試了相對和絕對 Xpath 均未成功。 我正在嘗試單擊該按鈕。

相對路徑: click = webdriver.find.element_by_xpath("//onboarding-mobile-fixed-bottom-container/div[1]/div/sprout-button/button").click()

絕對路徑: /html/body/cfapp-root/main/cfapp-spa-host/main/onboarding-root/div/div[1]/main/onboarding-business-phone/section/form/onboarding-next-button/onboarding-mobile-fixed-bottom-container/div[2]/sprout-button/button

absolute = webdriver.find.element_by_xpath("/html/body/cfapp-root/main/cfapp-spa-host/main/onboarding-root/div/div[1]/main/onboarding-business-phone/section/form/onboarding-next-button/onboarding-mobile-fixed-bottom-container/div[2]/sprout-button/button").click()

即使使用絕對的 xpath(我知道,練習時皺眉)我也無法點擊按鈕。

作為參考,我正在自動化:站點: https://account.kabbage.com/onboarding/data/number-of-employees; 用戶名:testingoverflow@aol.com; 密碼:Kabbage123

(點擊完成申請;完成申請;在繼續框上工作)

任何幫助深表感謝!!

from selenium import webdriver
from selenium.webdriver.common.keys import Keys
from time import sleep, strftime
from selenium.webdriver.support import expected_conditions as EC
from selenium.common.exceptions import TimeoutException
from selenium.webdriver.support.ui import WebDriverWait
from selenium.webdriver.common.by import By
import csv 
import xlrd

info = "info.xlsx"
openwb = xlrd.open_workbook(info)
inputws = openwb.sheet_by_index(0)

print(inputws.nrows)
print(inputws.ncols)

print(inputws.cell_value(1,0))

email_log = inputws.cell_value(2,0)
businesslog = inputws.cell_value(2,1)
firstname = inputws.cell_value(2,2)
lastname = inputws.cell_value(2,3)
phone = int(inputws.cell_value(2,4))
employees = int(inputws.cell_value(2,5))
business_types = inputws.cell_value(2,6)


print(email_log)
print(businesslog)
print(firstname)
print(lastname)
print(phone)

sleep(1)

chromedriver_path = 'C:/Users/Documents/Scale/Programs/chromedriver.exe' 
webdriver = webdriver.Chrome(executable_path=chromedriver_path)
webdriver.get('https://app.kabbage.com/signup/create_account')

sleep(1)
#input email
input_emails = webdriver.find_element_by_xpath('//*[@id="CreateAccount.EmailAddress_inner"]').send_keys(email_log)
sleep(1)
#re-input email
reinput = webdriver.find_element_by_xpath('//*[@id="CreateAccount.ConfirmEmail_inner"]').send_keys(email_log)

# Password
passwrd  = webdriver.find_element_by_xpath('//*[@id="CreateAccount.CreatePassword"]')
sleep(1)
passwrd.send_keys('Paycheck11!!')
sleep(1)
button_started = webdriver.find_element_by_class_name("btn-full-width").click()

sleep(5)

#ApplyNow

#apply = webdriver.find_element_by_class_name('spr-btn spr-btn-primary')

#apply = webdriver.find_elements_by_class_name("spr-btn-primary").click()

#xpath("//div[@class='fc-day-content' and text()='15']")

applynow = webdriver.find_element_by_xpath("//sprout-button/button[contains(@class, 'spr-btn-primary')]").click()

sleep(5)

applyfinal = webdriver.find_element_by_xpath("//sprout-button/button[contains(@class, 'spr-btn-primary')]").click()

sleep(5)

business_name = webdriver.find_element_by_xpath('//*[@id="businessName-input"]').send_keys(businesslog)
business_send = webdriver.find_element_by_xpath("/html/body/cfapp-root/main/cfapp-spa-host/main/onboarding-root/div/div[1]/main/onboarding-business-name/section/form/onboarding-next-button/onboarding-mobile-fixed-bottom-container/div[2]/sprout-button/button").click()

sleep(5)

first_name = webdriver.find_element_by_xpath('//*[@id="lastName-input"]').send_keys(lastname)
last_name = webdriver.find_element_by_xpath('//*[@id="firstName-input"]').send_keys(firstname)
names_send = webdriver.find_element_by_xpath("/html/body/cfapp-root/main/cfapp-spa-host/main/onboarding-root/div/div[1]/main/onboarding-personal-name/section/form/onboarding-next-button/onboarding-mobile-fixed-bottom-container/div[2]/sprout-button/button").click()

sleep(5)

phone_num = webdriver.find_element_by_xpath('//*[@id="businessPhone-input"]').send_keys(phone)
phone_check = webdriver.find_element_by_xpath('//html/body/cfapp-root/main/cfapp-spa-host/main/onboarding-root/div/div[1]/main/onboarding-business-phone/section/form/kbg-consent-box/div/sprout-checkbox/div/label').click()
#phone_send = names_send = webdriver.find_element_by_xpath("/html/body/cfapp-root/main/cfapp-spa-host/main/onboarding-root/div/div[1]/main/onboarding-personal-name/section/form/onboarding-next-button/onboarding-mobile-fixed-bottom-container/div[2]/sprout-button/button").click()
phone_submits = webdriver.find_element_by_xpath("/html/body/cfapp-root/main/cfapp-spa-host/main/onboarding-root/div/div[1]/main/onboarding-business-phone/section/form/onboarding-next-button/onboarding-mobile-fixed-bottom-container/div[2]/sprout-button/button").click()

sleep(5)

num_empl = webdriver.find_element_by_xpath('//*[@id="numberOfEmployees-input"]').send_keys(employees)
#emp_submit = webdriver.find_element_by_xpath("//sprout-button/button[contains(@class, 'spr-btn-block')][2]").click()
sending = webdriver.find.element_by_xpath("//button[@class='spr-btn spr-btn-primary' and contains(text(),'Continue')]").click()

您可以使用以下任何 Xpath:正確的相對 XPath 用於繼續按鈕

Xpath 1:

 *//onboarding-next-button//onboarding-mobile-fixed-bottom-container//div[2]//sprout-button//button[contains(text(),Continue)]

Xpath 2:

*//sprout-button[@class='desktop-button']//button[contains(text(),Continue)]

給這個 go:

webdriver.find_element_by_xpath("//button[@class="spr-btn spr-btn-primary" and contains(text(),'Continue')]").click()

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM