Common Selector Strategies
- used some help from: https://automationpanda.com/2018/06/15/web-element-clicks-with-selenium-webdriver/
Page Title
return driver.getTitle();
findElement(By.id
element = driver.findElement(By.id("edit-field-tags-target-id")); return element;
findElement(By.xpath
element = driver.findElement(By.xpath("//iframe[@title='Rich Text Editor, Body field']"));
Explicit Waits
int timeoutSec = 15; WebDriverWait wait = new WebDriverWait(driver, timeoutSec); wait.until((driver) -> driver.findElements(By.xpath("//a[@href='/uc/user/login']")).size()>0); wait.until((driver) -> driver.findElement(By.xpath("//a[@href='/uc/user/login']")).isDisplayed());
Drupal 8 iframe For Entering Article Body Text
element = driver.findElement(By.xpath("//iframe[@title='Rich Text Editor, Body field']")); //click into the iframe so text can be entered element.click(); return element;
Moving to frame Element
driver.switchTo().frame("mainpanel");
OR
el = driver.findElement(By.xpath("//frame[@name='mainpanel']")); driver.switchTo().frame(el);
MouseOver for Menu Elements
//mouse over the menu item Actions action = new Actions(driver); //new action // findElement.... build action to MOVE to element.... action.moveToElement(driver.findElement(By.xpath("//a[contains(.,'Contacts')]"))).build().perform(); // THEN click action.moveToElement(driver.findElement(By.xpath("//a[contains(.,'New Contact')]"))).build().perform(); el = driver.findElement(By.xpath("//a[contains(.,'New Contact')]")); el.click();
- Log in to post comments