[英]selenium webdriver - construct action click and sendkeys
我有一堆以下作品:
WebElement L3_Y1_total_x = driver.findElement(By.xpath("//input[contains(@class,'sumCell blahblah total')]"));
String L3_Y1_total_x1_value = L3_Y1_total_x.getAttribute("value");
WebElement L3_C1 = driver.findElement(By.xpath("//input[contains(@class,'cell blahblah1 decimal')]"));
L3_C1.click();L3_C1.sendKeys("3,00");L3_C1.sendKeys(Keys.TAB);
try {wait10s.until(Attribute_Not_To_Be.attributeNotToBe(L3_Y1_total_x, "value", L3_Y1_total_x1_value));} catch (TimeoutException e) {};
String L3_Y2_total_x1_value = L3_Y2_total_x.getAttribute("value");
WebElement L3_C2 = driver.findElement(By.xpath("//input[contains(@class,'cell cell blahblah2 decimal')]"));
L3_C2.click();L3_C2.sendKeys("3,00");L3_C2.sendKeys(Keys.TAB);
try {wait10s.until(Attribute_Not_To_Be.attributeNotToBe(L3_Y2_total_x, "value", L3_Y2_total_x1_value));} catch (TimeoutException e) {};
String L3_Y3_total_x1_value = L3_Y3_total_x.getAttribute("value");
WebElement L3_C3 = driver.findElement(By.xpath("//input[contains(@class,'cell blahblah3 decimal')]"));
L3_C3.click();L3_C3.sendKeys("3,00");L3_C3.sendKeys(Keys.TAB);
try {wait10s.until(Attribute_Not_To_Be.attributeNotToBe(L3_Y3_total_x, "value", L3_Y3_total_x1_value));} catch (TimeoutException e) {};
如何縮小代碼? 至少是element.click();element.sendKeys("xy");...
序列。
謝謝
這樣的事情應該適合您的目的(盡管我現在無法嘗試)。 使用L3_Y1_total_x
, L3_Y2_total_x
和L3_Y3_total_x
以及相應的參數blahblah
調用該函數。
public void doAction(WebElement elem, String blahblah) {
String value = elem.getAttribute("value");
WebElement L3_C1 = driver.findElement(By.xpath("//input[contains(@class,'cell " + blablah + "decimal')]"));
L3_C1.click();
L3_C1.sendKeys("3,00");
L3_C1.sendKeys(Keys.TAB);
try {
wait10s.until(Attribute_Not_To_Be.attributeNotToBe(elem, "value", value));
} catch (TimeoutException e) {};
}
請注意,使用下划線以及大寫變量會違反廣泛接受的Java編碼約定。 使用駝色大小寫和小寫變量。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.