I want to call a function after selenium sees and get the text of a link on page,
driver.get("https://www.guerrillamail.com/");
driver.findElement(By.id('inbox-id')).getText().then(function(gm){
address = gm + "@sharklasers.com";
var output = new Buffer(address, 'hex');
console.log(output);
mailExistsCheck();
var query = driver.wait(until.elementLocated(By.xpath("//*[contains(text(), '[email protected] ')]")));
query.click();
var query2 = driver.wait(until.elementLocated(By.partialLinkText("iptlogin")));
query2.getText();
var target = query2.getText();
aftter selenium finds this driver.wait(until.elementLocated(By.partialLinkText("iptlogin"))); I want to start a function called activateMail(target).
i Need to do something simular to this
var link = target.includes("iptlogin");
if (link = true) {
activateMail(target);
console.log("True");
}
2 Answers 2
@Devin, If you wants to run Javascript with selenium web driver use JavaScriptExecutor method, with the Following syntax :
JavascriptExecutor js = (JavascriptExecutor) driver;
js.executeScript(" var link = target.includes('iptlogin'); if (link == true) { activateMail(target); console.log('True'); } ");
1 Comment
' instead of ", else it breaks the syntaxYou will use something like below
driver.wait(until.elementLocated(By.partialLinkText("iptlogin"))).then(
() => driver.executeScript("activateMail()")
)
or you can even use it like below
driver.wait(until.elementLocated(By.partialLinkText("iptlogin")))
driver.isElementPresent(by.partialLinkText('iptlogin')).then(
() => driver.executeScript("activateMail()")
)
2nd one makes sure the element is present then only the function is executed. First one doesn't gurantee that
Comments
Explore related questions
See similar questions with these tags.
activateMail().