简体   繁体   中英

Selenium in Python: how to click non-English link?

I want to find a link by its text but it's written in non-English characters (Hebrew to be precise, if that matters). The "find_element_by_link_text('link_text')" method would have otherwise suited my needs, but here it fails. Any idea how I can do that? Thanks.

In the future you need to pastebin a representative snippet of your code, and certainly a traceback. I'm going to assume that when you say "the code does not compile" that you mean that you get an exception telling you you haven't declared an encoding.

You need a line at the top of your file that looks like # -*- coding: utf-8 -*- or whatever encoding the literals you've put in your file are in.

You should be able to enter your Hebrew search text in your code, as long as you tell the Python compiler what encoding you're using for the file. PEP 263 describes how to do this. Basically, you need to put a "magic" comment as the first or second line of your source file, looking like this:

# coding: utf-8

You don't have to use utf-8 either, just put whatever encoding you are using (as long as it's one that Python can decode).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM