我似乎遇到了问题.我有一个查询字符串,其值可以包含单引号.这将破坏查询字符串.所以,我试图做一个替代改变'对\'.
这是一个示例代码:
"This is' it".replace("'", "\'");
Run Code Online (Sandbox Code Playgroud)
这个输出仍然是:
"This is' it".
Run Code Online (Sandbox Code Playgroud)
它认为我只是为报价做一个转义字符.
所以我尝试了这两段代码:
"This is' it".replace("'", "\\'"); // \\ for the backslash, and a ' char
"This is' it".replace("'", "\\\'"); // \\ for the backslash, and \' for the ' char
Run Code Online (Sandbox Code Playgroud)
以上两个STILL都会产生相同的输出:
"This is' it"
Run Code Online (Sandbox Code Playgroud)
我似乎只能通过以下方式实现这一点:
"This is' it".replace("'", "\\\\'");
Run Code Online (Sandbox Code Playgroud)
结果如下:
"This is\\' it"
Run Code Online (Sandbox Code Playgroud)
有什么建议?我只是想更换一个'同\'.
它似乎不应该那么困难.
我们正准备将我们的自动化节点迁移到Windows 10,在我们的测试中,我们发现尽管我们的脚本在FF,IE和Chrome上的Win7上运行良好,但它们在Windows 10上仅在IE上失败(适用于FF和Chrome) ).
当运行agianst IE时,浏览器实例化并且webdriver能够看到浏览器(我尝试了一个简单的命令,如driver.back(),返回上一页).但是,我们无法获得任何find_element ...调用工作.无论是id,name,css,xpath等,脚本都会失败,说明找不到给定id/name/css/xpath的元素(无论我试图用什么方法来查找webelement).
我已经看到有关安全更新的帖子打破了这一点,并建议还原更新.这是一年前的事情,似乎随后的更新已经解决了这个问题.
我还阅读了有关确保所有区域的保护模式相同,注册表值等的帖子.这些建议都没有奏效.
以下是我正在使用的示例脚本(当修改为在Chrome或Firefox中运行时)仅在IE11中不起作用:
from selenium import webdriver
from selenium.webdriver.common.keys import Keys
driver = webdriver.Ie()
driver.implicitly_wait(30)
driver.maximize_window()
# navigate to the application home page
driver.get("http://www.google.com")
# get the search textbox
search_field = driver.find_element_by_id("lst-ib")
Run Code Online (Sandbox Code Playgroud)
运行此脚本的错误是:
selenium.common.exceptions.NoSuchElementException: Message: Unable to find element with id == lst-ib
Run Code Online (Sandbox Code Playgroud) python selenium selenium-webdriver internet-explorer-11 selenium-iedriver