1

I has this code that searches through text by XPath. The problem is that the searched text may contain Latin characters like ñor í.

I encoded it and when I print it, it shows perfectly, but when I use the XPath the encoding changes, and obviously it can't be found.

The decoded var prints well:

nombre_act = "HOTEL DIEGO DE ALMAGRO SAN PEDRO DE ATACAMA"
nombre_act = nombre_act.decode("utf8")

nombre_contrato = "Campaña Cyber Day, Desayuno Incluído"
nombre_contrato = nombre_contrato.decode("utf8")
print nombre_contrato

xpath = "//select[@name='"+nombre_act+"']/option[text()='"+nombre_contrato+"']"
print xpath
hotel_sel = driver.find_element_by_xpath(xpath).click()

console

1
  • Adding html sample will help to provide exact answer Commented Nov 27, 2018 at 5:36

1 Answer 1

1

Your code trials were near perfect. However I feel you don't need to change through encoding/decoding unless you want to print the characters to the console as follows:

nombre_act_actual = "HOTEL DIEGO DE ALMAGRO SAN PEDRO DE ATACAMA"
#nombre_act = nombre_act_actual.encode("utf-8")

nombre_contrato_actual = "Campaña Cyber Day, Desayuno Incluído"
nombre_contrato = nombre_contrato_actual.encode("utf-8") #required as you need to print to the console
print nombre_contrato

xpath = "//select[@name='"+nombre_act_actual+"']/option[text()='"+nombre_contrato_actual+"']"
hotel_sel = driver.find_element_by_xpath(xpath).click()

However, your another issue is the incompatibility between the version of the binaries you are using as follows:

  • You are using chromedriver=2.41
  • Release Notes of chromedriver=2.41 clearly mentions the following :

Supports Chrome v67-69

  • You are using chrome=70.0
  • Release Notes of ChromeDriver v2.44 clearly mentions the following :

Supports Chrome v69-71

So there is a clear mismatch between ChromeDriver v2.41 and the Chrome Browser v70.0

Solution

  • Upgrade ChromeDriver to current ChromeDriver v2.44 level.
  • Keep Chrome version between Chrome v69-71 levels. (as per ChromeDriver v2.44 release notes)
  • Clean your Project Workspace through your IDE and Rebuild your project with required dependencies only.
  • If your base Web Client version is too old, then uninstall it through Revo Uninstaller and install a recent GA and released version of Web Client.
  • Execute your @Test.
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.