Hi,
I would like to create one script which iterate on every mail button on this page.
There are a random Email button according to the research page like that :
and i would like to iterate on each “Email” Button :
Can someone help me please ?
Hi,
I would like to create one script which iterate on every mail button on this page.
There are a random Email button according to the research page like that :
and i would like to iterate on each “Email” Button :
Can someone help me please ?
Does clicking an “E-Mail” button redirect the user? (Does it cause the page to reload?)
Yes of course.
In the new page
But for the moment, i just would like to count how many Email button i have and click on the first “Email” Button on this research page, the second, the third …etc
for me, it’s very very complicated not like with UFT
Right, but the redirects matter, that’s why I ask.
Let’s say you build a list of the button elements currently on the page:
WebDriver driver = DriverFactory.getWebDriver()
List<WebElement> buttons = driver.findElements(By.xpath("//a[@title='E-Mail']"))
Then you decide to click on the first one:
buttons.get(0).click()
Your list will become “stale”, because a redirect wipes out the DOM, and repopulates it. So to avoid this, you will also need to re-grab the list after each iteration:
WebDriver driver = DriverFactory.getWebDriver()
List<WebElement> buttons = driver.findElements(By.xpath("//a[@title='E-Mail']"))
for(WebElement button : buttons) {
button.click()
// Code to wait for page to load...
// Code to navigate back to the "research page", if any?
buttons = driver.findElements(By.xpath("//a[@title='E-Mail']"))
}
I have this error :
08-07-2019 11:50:05 PM Test Cases/Connexion_et_envoi_Mail_IDF
Elapsed time: 8,758s
Test Cases/Connexion_et_envoi_Mail_IDF FAILED.
Reason:
org.codehaus.groovy.control.MultipleCompilationErrorsException: startup failed:
file:/C:/Users/33695/Katalon%20Studio/CNES.prj/Scripts/Connexion_et_envoi_Mail_IDF/Script1565207474218.groovy: 36: unable to resolve class WebDriver
@ line 36, column 11.
WebDriver driver = DriverFactory.getWebDriver()
^
When i tape this :
import static com.kms.katalon.core.checkpoint.CheckpointFactory.findCheckpoint
import static com.kms.katalon.core.testcase.TestCaseFactory.findTestCase
import static com.kms.katalon.core.testdata.TestDataFactory.findTestData
import static com.kms.katalon.core.testobject.ObjectRepository.findTestObject
import com.kms.katalon.core.checkpoint.Checkpoint as Checkpoint
import com.kms.katalon.core.cucumber.keyword.CucumberBuiltinKeywords as CucumberKW
import com.kms.katalon.core.mobile.keyword.MobileBuiltInKeywords as Mobile
import com.kms.katalon.core.model.FailureHandling as FailureHandling
import com.kms.katalon.core.testcase.TestCase as TestCase
import com.kms.katalon.core.testdata.TestData as TestData
import com.kms.katalon.core.testobject.TestObject as TestObject
import com.kms.katalon.core.webservice.keyword.WSBuiltInKeywords as WS
import com.kms.katalon.core.webui.keyword.WebUiBuiltInKeywords as WebUI
import internal.GlobalVariable as GlobalVariable
import org.openqa.selenium.Keys as Keys
WebUI.navigateToUrl(‘https://www.pagesjaunes.fr/’)
WebUI.setText(findTestObject(‘Pagesjaunes/Page_Accueil/input_quoi qui _quoiqui’),
‘architecte’)
WebUI.setText(findTestObject(‘Pagesjaunes/Page_Accueil/input_o _ou’),
‘ile-de-france’)
WebUI.click(findTestObject(‘Pagesjaunes/Page_Accueil/i_A proximit_icon icon-search’))
//aide brandon_hein
WebDriver driver = DriverFactory.getWebDriver()
List buttons = driver.findElements(By.xpath("//a[@title=‘E-Mail’]"))
buttons.get(0).click()
?
You need to import the relevant classes, as always.
Press ctrl + shift + o
on your keyboard.
Thanks u very much.
Now, i don’t know how to leave the browser open at the end of execution ?
How it’s possible to highlight button too please ?
because i don’t see this
These are separate questions that deserve separate topics.