0

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");
}
3
  • So what is the issue you are facing ? Commented Mar 26, 2018 at 11:59
  • I Edited Question Commented Mar 26, 2018 at 12:08
  • Your locator will find the element you are looking for. If it doesn't find it, the wait will throw a timeout exception. If the exception isn't thrown, call activateMail(). Commented Mar 26, 2018 at 13:30

2 Answers 2

1

@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'); } ");
Tarun Lalwani
147k11 gold badges218 silver badges279 bronze badges
answered Mar 26, 2018 at 13:23
Sign up to request clarification or add additional context in comments.

1 Comment

Have the fixed the syntax errors. You needed to use ' instead of ", else it breaks the syntax
0

You 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

answered Mar 26, 2018 at 14:01

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.