Selenium ignores links?

22 views
Skip to first unread message

Campo

unread,
Aug 23, 2016, 3:22:01 AM8/23/16
to Selenium Users
Hey guys,
I've a (maybe) simple question.

I currently use selenium to remove some posts in a phpbb3 board (allowed by the board so far).
For this procedure, I login with selenium, open the search form and search all my posts.

In the next step, selenium opens for every post a new tab (one at a time). In the new tab, selenium searches for all edit-buttons, opens them (one at a time again)
in a new tab, edit the content of the post and submits the form (see the code below).

Now I've the problem, that the edit-buttons doesn't get clicked sometimes.

I'll try to post a little piece of code here.



private void openElementInNewTab(WebElement element) {
    element
.sendKeys(Keys.CONTROL, Keys.RETURN);

   
WebElement bodyElement = driver.findElement(By.tagName("body"));
bodyElement.sendKeys(Keys.CONTROL,Keys.TAB);

   
driver.switchTo().window(windowHandle);
   
windowHandle = driver.getWindowHandle();
}

private void editPostsRoutine() {
    List<WebElement> editButtons = driver.findElements(By.linkText("Edit Post"));

for(WebElement editButton : editButtons) {
openPost(editButton);
       
WebElement messageElement = driver.findElement(By.id("message"));

if(!messageElement.getText().equals(postReplaceText) {
messageElement.clear();
messageElement.sendKeys(postReplaceText);
WebElement submitButton = driver.findElement(By.cssSelector(".button1.default-submit-action"));
submitButton
.click();
       
}
closeTab();
   
}
}

If you need other snippets - just tell me!
I also tried to use:
driver.wait(...).until(EC.presenceOfAllElementsLocatedBy(...))

Info: This happens only to some links (e.g. edit buttons), I don't know, why it works sometimes, and sometimes not.

Would be nice, if someone could spend some time for a solution.
Regards

Shubham Agarwal

unread,
Sep 26, 2016, 9:31:09 AM9/26/16
to Selenium Users
Hi Campo ,

Try adding explicit wait before clicking the edit buttons , because may be sometime it is taking time to load.
Reply all
Reply to author
Forward
0 new messages