开发者

Selenium and Python: remove \n from returned selenium.get_text()

When I call selenium.get_text("foo") on a certain element it returns back a different value depending on what browser I am working in due to the way each browser handles newlines.开发者_JS百科

Example:

An elements string is "hello[newline]how are you today?[newline]Very well, thank you."

When selenium gets this back from IE it gets the string "hello\nhow are you today?\nVery well, thank you."

When selenium gets this back from Firefox it gets the string "hello\n how are you today?\n Very well, thank you."

(Notice that IE changes [newline] into '\n' and Firefox changes it into '\n ')

Is there anyway using selenium/python that I can easily strip out this discrepancy?

I thought about using .replace("\n ", "\n"), but that would cause issues if there was an intended space after a newline (for whatever reason).

Any ideas?


I ended up just doing a check of what browser I was running and then returning the string with the '\n ' replaced with '\n' if the browser was firefox.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜