-2

I'm currently attempting to automate some of our manual testing in my place of work.

My current issue, is that WebDriver navigates to the URL, but doesn't seem to click on the button. Normally it would say 'Extension Updated Successfully'. I thought perhaps it was navigating to quickly away, so I added an implicit wait, but still face the same issue.

Random Info: Using Java, Windows 10, Selenium 3.

Updated due to feedback:

Here is the link to site. MyExtension

I'm attempting to click on this ExtensionButton before continuing, because I need to update extensions based on the site i'm logging into.

Here's the code I currently have, i've tried to use XPath, cssSelectors, byId, byClass. It's worked 1-2 times, each method.

 driver.get("https://account.walkme.com/ExtensionDownload/downloadPage.html?guid=f0dfc80b60f744d08ae38b7b41d8b852&customer=sarah_i&profile=default");
      wait.until(ExpectedConditions.visibilityOfElementLocated((By.xpath("//a[@id='extension-link']//span[@class='button-text']"))));
      driver.findElement(By.id("extension-link")).click();
      driver.manage().timeouts().implicitlyWait(20, TimeUnit.SECONDS);

Here's a snippet of the HTML:

            <img id="image" class="customer-icon">
            <div id="div-company">
                <label id="lbl-company">Company:</label>
                <span id="company">SFQA</span>
            </div>
            <div id="div-profile">
                <label id="lbl-profile">Profile:</label>
                <span id="profile">milton</span>
            </div>
            <div id="div-description" class="description-wrapper">
                <label id="lbl-description">Description:</label>
                <span id="description"></span>
            </div>

            <div id="customer" class="customer"></div>

            <a id="extension-link" class="orange-button update" style="cursor: pointer; display: inline-block;">
                <div class="button-icon"></div>
                <span class="button-text">Update Extension</span>
            </a>

             <a id="extension-link-upgrade" class="orange-button">
                <div class="button-icon"></div>
                <span class="button-text"></span>
            </a>


            <ul id="instructions" class="instructions">
                <li id="step-1">
                    <div class="step-num">Step 1 - </div>
                    <div class="step-image">
                    </div>
                </li>
                <li id="step-2">
                    <div class="step-num">Step 2 - </div>
                    <div class="step-image"></div>
                </li>
                <li id="step-3">
                    <div class="step-num">Step 3 - </div>
                    <div class="step-image"></div>
                </li>
                <li id="step-4">
                    <div class="step-num">Step 4 - </div>
                    <div class="step-image"></div>
                </li>
                <li id="step-5">
                    <div class="step-num">Step 5 - </div>
                    <div class="step-image"></div>
                </li>
                <li id="step-6">
                    <div class="step-num">Step 6 - </div>
                    <div class="step-image"></div>
                </li>
                <li id="step-7">
                    <div class="step-num">Step 7 - </div>
                    <div class="step-image"></div>
                </li>
                <li id="step-8">
                    <div class="step-num">Step 8 - </div>
                    <div class="step-image"></div>
                </li>
                <li id="step-9">
                    <div class="step-num">Step 9 - </div>
                    <div class="step-image"></div>
                </li>
                <li id="step-10">
                    <div class="step-num">Step 10 - </div>
                    <div class="step-image"></div>
                </li>
                <li id="step-11">
                    <div class="step-num">Step 11 - </div>
                    <div class="step-image"></div>
                </li>
                <li id="step-12">
                    <div class="step-num">Step 12 - </div>
                    <div class="step-image"></div>
                </li>
            </ul>

I'm attempting to click on line 16-18.

<a id="extension-link" class="orange-button update" style="cursor: pointer; display: inline-block;">
                <div class="button-icon"></div>
                <span class="button-text">Update Extension</span>
            </a>
E_net4
  • 27,810
  • 13
  • 101
  • 139
  • Did you try clicking on the span tag? using css selector "a.orange-button span .button-text" – Moe Ghafari Apr 11 '17 at 23:35
  • It worked once, haven't been able to get it to work again. It's weird because I have an implicit wait for 20 seconds, to see the 'Extension Updated' message and it skips over that. – Milton Mendieta Apr 12 '17 at 18:00

7 Answers7

1

If you're facing any abnormal difficulty which you are not able to handle directly , then you can first try to move to that element using actions class then click it as below:

WebElement we = driver.findElement(By.cssSelector("a#extension-link");
 Actions action = new Actions(driver);
 action.moveToElement(we).click().build().perform();
Kushal Bhalaik
  • 3,349
  • 5
  • 23
  • 46
0

According to HTML standards, the ID should be unique on the page. Given the HTML you provided, you should be able to use

driver.findElement(By.id("extension-link")).click();
JeffC
  • 22,180
  • 5
  • 32
  • 55
  • What does "doesn't work" mean? Throws an error, etc? What message are you getting? – JeffC Apr 12 '17 at 17:51
  • It basically skips over it. It goes to the site, looks at the element doesn't click it. Continues the script. – Milton Mendieta Apr 12 '17 at 18:22
  • It clicking something or it wouldn't move on. If it wasn't found or wasn't visible or wasn't clickable, you'd get an error. That means that you are trying to click the wrong thing or something else is going on but you aren't providing enough info for us to determine what the issue is. – JeffC Apr 12 '17 at 18:56
  • This is me running the program. You can see it goes through it,and continues to the next URL, without clicking. [link]https://www.screencast.com/t/RGrpHYfqlg – Milton Mendieta Apr 12 '17 at 18:59
  • I don't know what else to tell you. You have provided one line of HTML and I have provided code that should click that element. If you want us to be able to help you more, you need to do some debugging on your own and then edit your question with what you found. Post more of the relevant code, post more of the relevant HTML, a link to the page, etc. – JeffC Apr 12 '17 at 19:05
  • Hey JeffC, great thank you for the feedback. I will update to provide the relevant information. – Milton Mendieta Apr 12 '17 at 20:24
  • I've just looked again at this. you can get around this problem by using javascriptexcecutor - Run the following script as a work around and it should result with exactly what you want "_buttonElement.click()" They have it defined globally in the view – Moe Ghafari Apr 12 '17 at 21:45
  • You don't want to use JSE if you are trying to do user scenarios because no user can click a link using JS. – JeffC Apr 12 '17 at 22:22
  • how about document.getElementById("extension-link").click()? Can you use JSE to run that? i've tried it 5 times in a row and all worked. Would that be an acceptable user scenario? – Moe Ghafari Apr 13 '17 at 00:12
  • This ended up working fine. It was a matter of no success message, that was throwing me off. Made a horrible assumption, that since there was no success message that the extension wasn't being updated. But I checked it after with a test, and it is working fine regardless of getting a success message. – Milton Mendieta Apr 14 '17 at 22:40
0

What error are you getting when it doesn't click. If selenium doesn't perform action then it throws exceptions:

  • NoSuchElementException
  • ElemnentNotVisible
  • ElementNotClickable

Additionally, perform few checks to confirm if the element can be identified on the web page or not.

Element Present check:

`if(driver.findElements(By.xpath("value")).size() != 0){
System.out.println("Element is Present");
}else{
System.out.println("Element is Absent");
}`
user968813
  • 314
  • 1
  • 4
  • 14
0
  driver.findElement(By.id("extension-link")).click();

This is working, it was a matter of not getting the confirmation, that threw me off. However, after checking my extension unique user, it updated regardless of seeing or not seeing the success message.

0

First you need to wait until your element appear properly:

WebDriverWait wait = new WebDriverWait(getDriverProvider().get(), 40);
wait.until(ExpectedConditions.visibilityOfElementLocated(By.cssSelector("#extension-link")));

Then try to click by executing javascript :

        JavascriptExecutor jse = (JavascriptExecutor) getDriverProvider().get();
    jse.executeScript("arguments[0].click();", driver.findElement(By.cssSelector("#extension-link")));
0

I was asked this question in an interview. Question is as follows

An element is completely loaded and visible in a webpage. while automation run, the element is not clicked even after it is completely present. but no error or exception is thrown. Selenium library does not support this button(any Action, Select, or Robot does not support). How will you do automation.

My answers:

  1. Will Use diff classes of selenium (Action, Select, etc)---->NO
  2. Will use Robot class of JAVA (Robot pointers can be diff in diff systems) So--->NO
  3. I will take the next page url after clicking this button and proceed with the automation ___> He said, "lets move to next question" :)
  • As it’s currently written, your answer is unclear. Please [edit] to add additional details that will help others understand how this addresses the question asked. You can find more information on how to write good answers [in the help center](/help/how-to-answer). – Community Dec 27 '22 at 14:05
-1

Class has property class="orange-button update", but you are using [@class='orange-button']. Try changing and see if it works. Also, please share error message if you are getting any.

Anish Pillai
  • 1,023
  • 7
  • 8
  • this class means this tag is member to two different classes; so we can pick it up by using any one of the class in conjunction with any other criteria – Kushal Bhalaik Apr 12 '17 at 05:36