WebDriver Faʻailoaina, Malamalama ma Faigofie Faʻatali Faʻataʻitaʻiga

O le a le eseʻesega i le va o le faʻatali faatali, manino le faʻatali ma le lelei faʻatali i WebDriver? Faʻapitoa lava, o le a le fesoʻotaʻiga i le va WebDriverWait ma FluentWait?

Nei o faʻataʻitaʻiga o le faʻaaogaina taʻitasi auala faʻatali i WebDriver ma Java.

Faatali faatalitali

An faatali faatalitali o le taʻu atu i le WebDriver e palota le DOM mo se aofaʻiga taimi peʻa taumafai e suʻe se elemeni poʻo ni elemeni pe a latou le vave maua. O le le faʻamautuina seti o 0. A maeʻa ona setiina, o le faʻatali faatalitali ua setiina mo le ola o le WebDriver mea faʻataʻitaʻiga.

Faʻataʻitaʻiga o le faʻaaogaina faʻatali faatalitali

WebDriver driver = new FirefoxDriver(); driver.manage().timeouts().implicitlyWait(10, TimeUnit.SECONDS); driver.get('http://somedomain/slow_loading_url'); WebElement dynamicElement = driver.findElement(By.id('dynamicElement'));

O afea e tatau ai ona tatou faʻaalia faʻatali lemu?

E masani lava, e le fautuaina e faʻaaoga ni faʻatali le mautonu, pe a mafai ona tatou faʻaaogaina ni faʻatali manino poʻo ni faʻatali lelei.



Faatali manino

An faatali manino o se tulafono e te faʻamatalaina e faʻatali mo se tuʻutuʻuga tulaga e tupu ae leʻi faʻaauau luma i le code. WebDriverWait e ala i le le masani ona valaʻau le ExpectedCondition i le 500 milliseconds seʻia oʻo i le taimi e toe foʻi manuia ai.

Faʻataʻitaʻiga o le faʻaaoga faʻatali manino

WebDriver driver = new FirefoxDriver(); driver.get('http://somedomain/someurl'); WebElement dynamicElement = (new WebDriverWait(driver, 10))
.until(ExpectedConditions.presenceOfElementLocated(By.id('dynamicElement')));

O afea e tatau ona tatou faʻaalia ai faʻatali manino?

E masani ona matou faʻatali faʻatali manino pe a fai e umi se taimi e ave ai se elemeni. Na matou faʻaaogaina faʻatali manino foi e siaki le meatotino a le CSS o se elemeni (iai, kilikiina. Etc.) e mafai ona suia i le Ajax talosaga.

Faatali lelei

A o faʻaaogaina le FluentWait faataitaiga, e mafai ona matou faʻamaoti mai:

  • Ole taimi e tatau ai e le FluentWait ona siaki ia tuutuuga ua faʻamatalaina.
  • Le amanaʻia faʻapitoa ituaiga o ese mai faʻatali pei o NoSuchElementExceptions a o suʻea se elemeni luga o le itulau.
  • Le aofaʻi maualuga o taimi e faʻatali ai mo se tuutuuga

Faʻataʻitaʻiga o le faʻaaogaina FluentWait

// Waiting 30 seconds for an element to be present on the page, checking // for its presence once every 5 seconds. Wait wait = new FluentWait(driver)
.withTimeout(30, SECONDS)
.pollingEvery(5, SECONDS)
.ignoring(NoSuchElementException.class); WebElement foo = wait.until(new Function() {
public WebElement apply(WebDriver driver) {
return driver.findElement(By.id('foo')); } });

O afea e tatau ai ona tatou faʻaaogaina FluentWait?

A e taumafai e faʻataʻitaʻi le i ai o se elemeni e ono aliali mai pe a maeʻa x sekone / minute.

Eseesega i le va WebDriverWait ma FluentWait

WebDriverWait o se vasega vasega o FluentWait. I le FluentWait e tele atu au filifiliga e teuteuina, faʻatasi ai ma le maualuga o le taimi faʻatali, pei o vaitaimi palota, tuusaunoa e le amanaʻia ai etc.

Ma, nai lo le faʻatali ona faʻaaoga lea findElement:

WebDriverWait wait = new WebDriverWait(driver, 18); wait.until(ExpectedConditions.elementToBeClickable(By.linkText('Account'))); WebElement element = driver.findElement(By.linkText('Account')); element.sendKeys(Keys.CONTROL); element.click();

e mafai ona matou faʻaaogaina:

WebElement element = wait.until(
ExpectedConditions.elementToBeClickable(By.linkText('Account')));

Faʻamatalaga atili: