Python 为什么我的xpath不能与selenium一起使用?
我需要写一个脚本,给定用户在我的网站上的输入,它连接到此页面以提交号码并下载文件。问题是,xpath根本不起作用。我做错了什么 这是观点(我删除了与问题无关的部分):Python 为什么我的xpath不能与selenium一起使用?,python,django,selenium,xpath,Python,Django,Selenium,Xpath,我需要写一个脚本,给定用户在我的网站上的输入,它连接到此页面以提交号码并下载文件。问题是,xpath根本不起作用。我做错了什么 这是观点(我删除了与问题无关的部分): 该网站也有一个验证码,我得到了一个方法来处理它,我是否也应该将验证码字段添加到driver.find_元素并将方法传递到那里?也许你的隐式等待方法是不够的。你应该试试等等。基本上,显式等待是您定义的代码,用于在代码中继续之前等待特定条件发生: 另一个原因可能是动态id。也许你的网站每次都会创建不同的Id。您应该找到其他没有每次更改
该网站也有一个验证码,我得到了一个方法来处理它,我是否也应该将验证码字段添加到driver.find_元素并将方法传递到那里?也许你的隐式等待方法是不够的。你应该试试等等。基本上,显式等待是您定义的代码,用于在代码中继续之前等待特定条件发生: 另一个原因可能是动态id。也许你的网站每次都会创建不同的Id。您应该找到其他没有每次更改的属性,然后根据该属性更改Xpath,或者您可以使用不需要任何特定属性名称的完整(绝对)Xpath
from django.shortcuts import render, HttpResponse
import requests
from django.views.generic import FormView
from time import sleep
from selenium import webdriver
class ConstanciaInscripcion(FormView):
def get(self, request):
return render(request, 'app/constancia-inscripcion.html')
def post(self,request):
form = MonotributoForm(request.POST)
email = request.POST['Email']
cuit_r = int(request.POST["CUIT"])
#Selenium script
DRIVER_PATH = 'C:/Users/python/chromedriver.exe'
driver = webdriver.Chrome(executable_path=DRIVER_PATH)
driver.get('https://seti.afip.gob.ar/padron-puc-constancia-internet/ConsultaConstanciaAction.do')
driver.implicitly_wait(20)
cuit = driver.find_element_by_xpath("//input[@id='cuit']").send_keys(cuit_r)
submit = driver.find_element_by_xpath("//input[@id='btnConsultar']").click()
return render(request, 'app/constancia-inscripcion.html')