如何用撇号处理xpath

时间:2018-07-09 02:07:48

标签: selenium xpath automation apostrophe

Web元素包含撇号,所以我不知道如何在Selenium自动化脚本中创建xpath。

脚本部分是

WebElement settingSection = FindElements(By.XPath(string.Format(".//*[.='{0}']", **category**))).FirstOrDefault(x => x.Displayed);

变量类别将为“ 排序'浏览出版物'过滤器:”,但在运行自动化程序时无法使用

enter image description here

我尝试了使用转义撇号的方法,但是它也不起作用。

enter image description here

enter image description here enter image description here

WebElement settingSection = FindElements(By.XPath(string.Format(".//*[.=\"{0}\"]", category))).FirstOrDefault(x => x.Displayed);

4 个答案:

答案 0 :(得分:0)

尝试

String category = "Sort \'Browse Publications\' filter:";
WebElement settingSection = FindElements(By.XPath(string.Format(".//*[.='{0}']", category))).FirstOrDefault(x => x.Displayed);

答案 1 :(得分:0)

尝试使用此xPath:

sudo jupyter notebook --allow-root

示例代码如下:

sudo chmod -R 777 .local

答案 2 :(得分:0)

尝试使用以下WebElement

WebElement settingSection=driver.findElement(By.xpath("//h3[text()=\"Sort 'Browse Publications' filter:\"]"));

答案 3 :(得分:0)

找出解决方案:

WebElement settingSection = FindElements(By.XPath(string.Format(".//*[.=\"{0}\"]", category))).FirstOrDefault(x => x.Displayed);