Абсолютный путь: Selenium Xpath не может определить элемент - PullRequest
0 голосов
/ 01 мая 2020

Я пытаюсь идентифицировать HTML кнопку с Xpath и попытался как относительный, так и абсолютный 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; Pw: Kabbage123

(нажмите Fini sh Применяется; Fini sh Применяется; работает над окном продолжения)

Любая помощь очень ценится !!

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/Adrian Bialonczyk/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()

Ответы [ 2 ]

2 голосов
/ 01 мая 2020

Вы можете использовать любой из следующих Xpath: Правильный относительный XPath для кнопки Continue

Xpath 1:

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

Xpath 2:

* // кнопка-росток [@ class = 'desktop-button'] // кнопка [содержит (текст (), продолжение)]

0 голосов
/ 01 мая 2020

Дайте это go:

webdriver.find_element_by_xpath("//button[@class="spr-btn spr-btn-primary" and contains(text(),'Continue')]").click()
Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...