每当我们传递包含相同内容的字符串时,括号就会从 Sendkey 方法中删除。任何建议如何克服这个?
The parenthesis get removed from Sendkey method whenever we pass a string containing the same. Any suggestion how to overcome this?
d1.findElementById("originlocation").sendKeys("Indira Gandhi Airport(DEL) near Delhi in India");
在文本框中输入文本时,括号会被完全删除。
(DEL) 更改为 DEL,但我们想要的是 (DEL) 原样。
这个问题似乎可以在 firefox 中重现。所以作为解决方法,您可以尝试使用:
d1.findElementById("originlocation").sendKeys("Indira Gandhi Airport(DEL) near Delhi in India"
.replace("(", Keys.chord(Keys.SHIFT, "9"))
.replace(")", Keys.chord(Keys.SHIFT, "0")));
您试过用单引号代替双引号吗?
可能是
d1.findElementById("originlocation").sendKeys('Indira Gandhi Airport(DEL) near Delhi in India');
有用吗?
只是一个建议。由于要将文本放入文本字段或 textarea 元素,另一个建议是使用文本设置元素的值,而不是使用 sendKeys。
我的问题已通过使用以下代码得到解决:
List<WebElement> items = d1.findElements(By.xpath("html/body/ul[1]/li/a"));
// look for item on list that contains Melbourne (MEL)
for(int i= 0; i <items.size();i++){
if(items.get(i).getText().contains("Indira Gandhi Airport(DEL)")){
items.get(i).click();
break;
}}
d1.findElementById("originlocation").sendKeys("Indira Gandhi Airport(DEL) near Delhi in India");
在文本框中输入文本时,括号会被完全删除。 (DEL) 更改为 DEL,但我们想要的是 (DEL) 原样。
这个问题似乎可以在 firefox 中重现。所以作为解决方法,您可以尝试使用:
d1.findElementById("originlocation").sendKeys("Indira Gandhi Airport(DEL) near Delhi in India"
.replace("(", Keys.chord(Keys.SHIFT, "9"))
.replace(")", Keys.chord(Keys.SHIFT, "0")));
您试过用单引号代替双引号吗?
可能是
d1.findElementById("originlocation").sendKeys('Indira Gandhi Airport(DEL) near Delhi in India');
有用吗?
只是一个建议。由于要将文本放入文本字段或 textarea 元素,另一个建议是使用文本设置元素的值,而不是使用 sendKeys。
我的问题已通过使用以下代码得到解决:
List<WebElement> items = d1.findElements(By.xpath("html/body/ul[1]/li/a"));
// look for item on list that contains Melbourne (MEL)
for(int i= 0; i <items.size();i++){
if(items.get(i).getText().contains("Indira Gandhi Airport(DEL)")){
items.get(i).click();
break;
}}