Error while interpreting special characters

Asked

Viewed 776 times

1

I’m looking for an element, and so far so good, I’ve tested it again and again, but.. by using this code

driver.find_element_by_xpath('//*[@data-qtip="Configurações"]').click()

gives an error, and the cmd returns me

  File "chrome.py", line 105, in tearDown
    driver.find_element_by_xpath('//*[@data-qtip="Configura├º├Áes"]').click()

clearly he is not finding why he is disfigured the "settings"

that same element, works normally

driver.find_element_by_xpath('//*[@data-qtip="Sem descrição."]').click() 

added to the code

#!/usr/bin/env python
# -*- coding: utf-8 -*-

however the problem persists, how to proceed?

  • Try to put it like this: r'//*[@data-qtip="Configurações"]', understand the r before the string. Or else it is u, I’m trying to remember.

  • still continues, what would be the function of r?

  • Ah no, the r is to disregard the \ as a special character, like \n for new line or \t for TAB. Tried with the u? I’m researching here right now. I’ve been through it but I can’t reproduce it now.

  • https://docs.python.org/2/tutorial/introduction.html#Unicode-strings

  • u also did not work, funny that above use the same xpath with the field "No Description" and works perfectly,

  • I could show you how the stretch that worked?

  • driver.find_element_by_xpath('//*[@data-Qtip="No description."]'). click()

Show 2 more comments

2 answers

0


The way I managed to solve:

driver.find_element_by_partial_link_text('Conf').click()

but I still can not understand why that way not Funiona.

0

Check that your file . py is saved as Unicode (UTF-8) and not ASCII/ANSI. Also I would use the prefix u in string: u'//*[@data-qtip="Configurações"]'

  • is being saved correctly, I edited the question with a similar example that is working, but in theory should not.

  • But Father. You put the line of error, but what is the message error?

  • has on the question. File "Chrome.py", line 105, in tearDown driver.find_element_by_xpath('//*[@data-Qtip="Configure º Áes"]'). click()

  • This is not an error message is just the error line. Without knowing which error even makes it difficult to figure out the problem. Most of the answers, including mine, figured it was a mistake of encoding just because the stack trace text got corrupted, but this may just be a command line problem or the tool used to print the error. The same error may have nothing to do with encoding.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.