[英]Selenium Webdriver error “The method sendKeys(CharSequence…) from the type WebElement refers to the missing type CharSequence”
[英]How to Prevent Selenium WebElement sendKeys() Method from Performing Parameter Substitution
我正在使用Selenium自動化來測試攻擊者可能發送的惡意字符串。 但是,我遇到了WebDriver.sendKeys(...)
方法的問題,其中文本值沒有按字面值發送給瀏覽器。
例如,字符串../../../../../../../../../../../etc/hosts
被自動修改,因此瀏覽器類似於/var/folders/<...>/hosts
。
導致問題的代碼:
public void enterCommentText(String text) {
WebElement textArea = driver.findElement(By.xpath(xpathForCommentTextArea()));
textArea.clear();
textArea.sendKeys(text);
}
textArea.sendKeys(text)
,字符串text
包含我要發送的文字文件路徑。 但是,出現在瀏覽器中的字符串已經過參數替換。 有沒有一種方法可以使sendKeys(text)
從字面上處理字符串值?
我當前的解決方法是一次從字符串中發送每個字符。
for(int i = 0; i < text.length(); i++) {
textArea.sendKeys(text.substring(i, i+1));
}
我正在使用Java 8,Selenium 3.8.1和Chrome 64.0.3282.186。
經過反復嘗試,我無法重現該問題。 sendKeys()
始終會發送原始路徑字符串,並且不會被修改。
可以嘗試的事情是:
(1)在System.out.println("Test:" + text);
添加一些(在.sendKeys()
之前添加一個,在其之后添加一個System.out.println("Test:" + text);
在驗證方法正確無誤的方法中,
(2)嘗試使用其他瀏覽器,
(3)嘗試使用相同的代碼,但在其他頁面(例如http://www.globalsqa.com/samplepagetest/
)上嘗試查看它是否是您正在嘗試解釋的應用程序。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.