0
Following the code, how to proceed in a loop to always repeat the same fill N times? Or even picking up the names from a list. txt and populating in "name"?
def teste(self):
driver = self.driver
driver.get("http://painelvix.com/galaxia4/formulario_testes.php?r=UUVJcFdZMXlZcE5XdVU2cGVEUjVMYllMNnVBYS9GajVVUkZ3em9tRDZObz0,")
driver.find_element_by_name("nome").click()
driver.find_element_by_name("nome").clear()
driver.find_element_by_name("nome").send_keys("Teste de preenchimento")
driver.find_element_by_name("email").click()
driver.find_element_by_name("email").clear()
driver.find_element_by_name("email").send_keys("[email protected]")
driver.find_element_by_name("perfil[]").click()
driver.find_element_by_xpath("//*/text()[normalize-space(.)='Solicitar']/parent::*").click()
self.assertEqual("Existe um teste pra este email cadastrado em: 28/03/2019", self.close_alert_and_get_its_text())
driver.close()
Plus the unittest:
if __name__ == "__main__":
unittest.main()
File link.
Thanks for the tip. But when you run the code, it doesn’t work, it opens only the url, but without any action. driver.find_element_by_name("name".format(k)). send_keys(k) .
– Hudson Souza
Sorry, I forgot to add the
{}
. I’ll edit– Lucas
@Hudsonsouza, try again, please. If it doesn’t work, try to make a replicable example, because then it’s easier to understand what you’re trying to do.
– Lucas
I put the link to the file. Basically it’s just filling a small form, with this, loop to fill N times with different names. Briefly, even more: fills sends, fills sends... :)
– Hudson Souza
@Hudsonsouza With its full code, it became much easier. See my new solution
– Lucas
Thank you, much succinct the code. Show!
– Hudson Souza
I think you can put the
driver = webdriver.Chrome()
out of the loop, after all already started, no need to re-install every time– Guilherme Nascimento
@Guilhermenascimento does this, generates an error after the first fill. Run on your PC to see
– Lucas
@Hartnäcking is because it is using driver.close without need also, it would suffice for it out of the loop also ... and of course independent from adjusting the code or not a Sleep can help notice the details, of course this will depend on what the AP will do with the code.
– Guilherme Nascimento
@Guilhermenascimento is true. I will edit the code to include these improvements
– Lucas
@Hartnäcking also has a deal to do, but this the AP did not even mention, which is about the Alerts that cause Exception, but only if he formulates a new question that you should answer ;) Have a good weekend
– Guilherme Nascimento
PS: I think it would be something +or- like the AP code: https://gist.github.com/brcontainer/89c286c237c0c710c0483ebface9c208 (for those curious about the abbreviations used on the site: https://pt.meta.stackoverflow.com/q/6311/3635)
– Guilherme Nascimento