Selenium IDE element not found select an option from dropdownlist - selenium

I'm new to selenium
My script is to:
open one website
click one button and then open go to another website
a drop down list will be shown in the new website, i need to select one option from the list
But I failed.
The log said:
Element id=primaryroles not found
I tried to change the target to detailed HTML element, like
//html/frameset/frame/html/body/form/table/tbody/tr/td/div[#id='clientBackground']/table/tbody/tr/td[2]/table/tbody/tr[3]/td/label/select
But it failed as well.
I think the problem may be that new website did not load fully, so i add command "waitforpagetoload" value30000 but the error is time run out
I run out of my brain, please help me :)
The weirdest thing is that i could execute this single command successfully, but i play this current test suit/case, it will fail when it come to this command.

As per the snapshot (without any visibility to your script) you have shared to select from the DropDown you have to use the following Algorithm :
Open one Website
Click one button and then open go to another website
Switch to the Frame with proper WebDriverWait
Use Select Class to identify the DropDown element.
Induce WebDriverWait for your target option to render in the HTML DOM
Click on the intended option

Related

Selenium didn't click second time after being reloaded to homepage

I have a test case here:
My page left part is an accordion menu. When I performed click parent menu, it worked. And the right part of the website will display "You do not have authority" and return me back to the homepage.
The right part will display normal content when I second visit. So I should click the menu again and I write like so in my test code. But it didn't perform any click action - just passed the click action to the next step. So my test fails and throws error.
I looked at my browser which is controlled by selenium webdriver. It is apparently frozen after the page reloads to the homepage.
The error message shows:
Test method AutomationTesting.cuteTest.CheckChocolate threw exception:
OpenQA.Selenium.WebDriverTimeoutException: Timed out after 5 seconds ---> OpenQA.Selenium.NoSuchElementException: no such element: Unable to locate element: {"method":"xpath","selector":"//*[#class='menuChocolate']/a"}
My test code: (Why I have to click the second time is because this page needs to come the second time to show the normal UI)
DessertsMenu.Click();
WebDriverWait waitForMenu= new WebDriverWait(Driver, TimeSpan.FromSeconds(5));
waitForMenu.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[#class='menuChocolate']/a"))).Click();
DessertsMenu.Click();
WebDriverWait waitAgain= new WebDriverWait(Driver, TimeSpan.FromSeconds(5));
waitAgain.Until(ExpectedConditions.ElementIsVisible(By.XPath("//*[#class='menuChocolate']/a"))).Click();
I looked at the browser which is controlled by selenium, it actually clicks the menu. But I don't know why it didn't click again.
Is there anything I am missing?
If the page is reloaded, I think you will have to locate the parent menu again.
If, even after locating the element, you are not able to click the parent menu, then I would suggest you to try clicking the parent menu using JavaScriptExecutor.
https://www.guru99.com/execute-javascript-selenium-webdriver.html
You can troubleshoot it with below options--
can you check after first click if it is showing the same xpath ,it might be possible that after clicking xpath is getting changed
you can put some wait like one second between first and second click
3.If above two options are not working then you can use JavaScriptExeccutor

Click not working on combo-box down arrow button karate UI testing

I tried clicking on down arrow button for a Combo Box (Select is not available. Its a React JS application and once I click on arrow button only list shows selection items) using below karate command but click not happened in application and no error displayed. [The same xpath worked in selenium click command,and showing unique item on Inspect search]
And waitFor("//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div")
And click("//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div")
Note: Then I tried below command
And assert('//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div').exists
and got error
javascript evaluation failed: assert('//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div').exists, :1:19 Expected , but found root
assert('//div[#id='root']/div/div[3]/main/div/div[3]/div[2]/div').exists
It would really help us if you follow this process, it is simple and should not take much time for you to give us a small snippet of static HTML (or you can mix react if really needed).
https://github.com/intuit/karate/tree/master/examples/ui-test
EDIT: you also seem to have mis-matched single and double-quotes in your code.
Also note that you should be able to fire a JS event or click by using the script() API. See this example: https://github.com/intuit/karate/tree/master/karate-core#script
So this is an alternate approach to be able to overcome any tricky situation that comes up.

Selection of Radio Button-Selenium IDE

I am new to Selenium IDE and need help in selection of radio buttons here. In my case, I am trying to generate a test case for a particular form consisting of radio buttons. When I run the command to select one of the radio buttons singly, the function works but if I run the whole test case then the radio button do not get selected and gives error of Element Id not found. Here is my html:
<input type="radio" value="0" id="ProjectSolutionsProject0" name="data[Project][solutions_project]">
My IDE command: click Target:id=ProjectSolutionsProject0 .
I tried verifyByValue , assertValue but nothing is working. Please help
From what you are describing, it appears the element may not be ready quite yet when you are trying to run the step. I have found that if an element is being dynamically generated it may take it longer to show up than Selenium wants to wait. There is a few ways to possibly fix this:
Use the waitForElementPresent command where id=ProjectSolutionsProject0 right before your current one to ensure that element has time to load.
Whatever command before that try changing it to a ...AndWait command instead to give the page time to load
Lastly you could try the waitForPageToLoad command right before this command and see if that allows the page to fully load first.
I recommend trying those options in that order to see which one would solve your problem.

Automating "Browse" button event in Selenium

I need to automate the "Browse" button click from Selenium.
For this, I have tried
driver.findElement(By.xpath("//*[#id=\"dnn_ctr383_View_filename\"]")).click();
and
driver.findElement(By.cssSelector("Css path")).click();
Both gives me org.openqa.selenium.NoSuchElementException: Unable to locate element: exception.
I have seen this link here where the author suggest to use AutoIT, but in step 2, the script, the author has created is for IE. Can someone please suggest, how I can automate the "Browse" button click in firefox?
Any help is much appreciated.
Directly send the file path to the id, like so
driver.findElement(By.id("dnn_ctr383_View_filename")).sendKeys("C:\\path\\to\\file");
The above step is the answer for your first two steps
Click on Browse
Select a file to upload
For the third step(click upload), looking at the screen capture I do not see any button which says "Upload". So just click "Save" and I assume that your file will successfully get uploaded.
There are two things that u need to consider here:
Clicking the browser button: Usually handled by an alert or popup, if the driver is not able to find the element by xpath(which u have acquired from firebug or chrome's inspect element) you should consider looking for iframes in the page source. If an element is in a different frame altogether , u need to switch frames in order to find the element like this
WebElement frame = driver.findElementById("name_of_iframe");
driver.switchTo().frame(fr);
now you can find your element using xpath or css selector like u did. Once completed u can move out of the frame by:- driver.switchTo().defaultContent();
Uploading the file from desktop: Since selenium works only on the html in the browser session u invoked from the driver, it can't perform operations on your desktop.Once you are able to click the browser button u can use Auto it(works only on windows) or Sikuli(works with mac, linux, windows and even android) to simulate your events based on the position of your upload button.
Hope this helps

Selenium cannot click tab in magento module detail page

I'm trying to validate data using selenium version 1.0.9 in magento grid and its detail page.
First, I walked through Selenium IDE from login page to module detail page and click the tabs available there. Eventually, IDE generates PHP codes so I put the code into proper location.
Note: Here, I have clicked the two tabs so that the events get recorded into selenium IDE.
Then, I run the code from command prompt using following command:
phpunit --configuration /var/www/tests/phpunit_test.xml
I got the error (something like):
ERROR: Element //a[#id='test_tabs_form_section']/span not found.
I modified the code and tried to open the detail page before executing click to above link i.e. "test_tabs_form_section", I am getting same error.
Another strange this is if I verify any text of detail page and remove the code that calls click to module detail tabs, it is works, not sure why?
But I really want to open detail page and click to tab, get forms element values using xpath and validate the data.
Can somebody help me, please?
Any help or suggestion is highly appreciable!
Looking forward to hear from stackoverflow geeks!
Thanks
In case this helps anybody:
I found out more things work if firebug is active. This actually makes sense cause firebug will show the final DOM tree in all it's debugging screens, so it's possible selenium is now able to reconstruct the element path because firebug altered the internal DOM.
If something doesn't work with the default element selection created by Selenium IDE, try switching it over to xpath:id-relative. You're already using that in your question, so maybe you there's an even better selector or you will need to resort to using clickAt instead of click.