Hello all the following codes works here it is.
String content = FileUtils.readFileToString(new File("C:\\PayrollSync\\prepayroll.txt"));
String [] Arrayclients = content.split("\n");
// begin for loop
for(String client : Arrayclients) {
PP_OBJ_CycleData.verifysearch(driver);
PP_OBJ_CycleData.searchbox(driver).clear();
PP_OBJ_CycleData.searchbox(driver).sendKeys(client);
PP_OBJ_CycleData.searchbox(driver).sendKeys(Keys.BACK_SPACE);
Thread.sleep(4000);
//WebElement dropdown = driver.findElement(By.xpath(".//*[@title="+client+"]"));
//dropdown.click();
//driver.findElement(By.xpath(".//*[(text(),"+client+"]")).click();
driver.findElement(By.xpath("//*[contains(text(),"+client+")]")).click();;
Thread.sleep(2000);
PP_OBJ_CycleData.practitioner(driver).click();
The Problem: None for the driver.findElements are working such as:
//WebElement dropdown = driver.findElement(By.xpath(".//*[@title="+client+"]"));
//dropdown.click();
//driver.findElement(By.xpath(".//*[(text(),"+client+"]")).click();
driver.findElement(By.xpath("//*[contains(text(),"+client+")]")).click();;
Thread.sleep(2000);
My failure traces says cannot find element By.xpath("//*[contains(text(),"+client+")]")). However I am waiting for the element to be visible when i go to the next page. My wait is below.
Wait<WebDriver> wait = new FluentWait<WebDriver>(driver).withTimeout(20, TimeUnit.SECONDS);
element = driver.findElement(By.id("toolbarQuickSearch"));
wait.until(ExpectedConditions.or(
ExpectedConditions.visibilityOf(element),
ExpectedConditions.elementToBeClickable(element)
));
The problem from what I can see if that after the variable that contains the string is entered into the search field and the string name is visible selenium cant find the string name to click on for example below:
I could put this in and it will click on it all the time:
driver.findElement(By.xpath("//*[text()='midrfrate']"]"));
However if i do something like this it cant find it:
driver.findElement(By.xpath(".//*[(text(),"+client+"]")).click();
driver.findElement(By.xpath("//[contains(text(),"+client+")]")).click();
Please help me I have tried the following with no success: How to use variables in XPath?
Your xpath there:
driver.findElement(By.xpath("//*[contains(text(),"+client+")]")).click();
:
Should contain apostrophes
Text in contains block should contain exact String (you have trailing whitespace in client variable 'midrfrate ').
Final xpath is:
driver.findElement(By.xpath("//*[contains(text(),'"+client.trim()+"')]")).click();
where trim() method removes leading and trailing whitespace from client variable.