Unable to break from the if condition and cannot click on element - selenium

I have a svg file and i need to click on the seats, So i have used driver.findelements() when a seat is clickable it should click on it and come out of the if condition. But when i use break it is not clicking the seat, When i do not use break it will go into infinite loop.
How do i break after the seat is selected.
Please find the attached code

Make recursive function which keeps on checking that element is enabled or not.
once it is enabled , it will click and come out.
def click_enabled_element(enable_value = False)
if enable_value:
i.click()
return
else:
click_enable_element(i.isEnabled())

Related

Tosca: How to scan Dropdown textbox which disapper upon opening xScan

I have a problem in scanning a drop-down menu which disappears upon opening the xScan. I need to get the module id of the dropdown menu to verify some test steps.
Do you have any solution with this if it is not really possible to get the module id of the dropdown menu?
Open developer tools in your browser of choice (F12), navigate to the console and input the following code:
var fulldoc='';
var scrollX=0;
var scrollY=0;
document.addEventListener("keydown",function(event){
if(event.key=='q' && event.altKey){
fulldoc=document.body.outerHTML;
scrollY=window.pageYOffset;
scrollX=window.pageXOffset;
}
if(event.key=='w' && event.altKey){
document.body.outerHTML=fulldoc;
document.body.scrollTo(scrollX,scrollY);
}
});
When the window looks the way you would want to scan, press 'Alt + Q', then press 'Alt + W'.
Now your window will freeze and then you can scan your page.
To steer the objects you need to refresh your browser.
You can resolve the issue with below 2 steps
1 - Add some text in textbox which will populate the dropdown below it .
2 - Use Send Keys Module to scroll down and select the value.
I had a similar issue where we had a popup that only appeared when clicking on a text box. The solution we received from the Tricentis trainer was as follows:
Part One
1. Open your application in Chrome
2. Right click the inspect
3. In the inspector window, on the Elements tab, navigate to your html element where it should be (you can do that by clicking on the element and check that you can see the html in the element)
4. Use the debugger to add a break point there, this should pause it and you should be able to see the elements you need to steer it.
5. Once you found the element, you will need the type of element (e.g. div, span, etc), and the class name
Part two
1. Rescan your module and select any element that matches the criteria of your element selected in Part One #5
2. Identify it by only it's class name property and tag
3. Save and close
4. Edit the element in the module view by changing the class name. This should help you steer it
Note: if the element class name is not unique, you might need to use Explicit name.
Good luck

How do I highlight the content of a TextBox/RefEdit control and set focus simultaneously?

I'd like to highlight the content of a TextBox/RefEdit control and set focus simultaneously when there is any invalid entry and after prompting a message box warning the error so that user knows where to fix the error. You can try Data>Analysis>DataAnalysis>Sampling and enter some invalid range/data, then you will be redirected to the invalid entry. The invalid entry is highlighted as well as with focus set (you can see a flickering cursor).
I tried to emulate this and I used,
aControl.SetFocus
aControlt.SelStart = 0
aControl.SelLength = Len(aControl.Text)
While the content inside the control is highlighted in blue, there's no flickering cursor as if I did not set focus of the control. How can I fix this? Or what's the best way to guide the user to the place where the invalid entry exists?
What if user inputs more than one invalid entries. How do you plan them all selected and setfocused at the same time.
There is no need to complicate things for you and for user. What you can do is create invisible labels with the right message you want to deliver to user, preferably in red color, and place them below each TextBox/RefEdit. Make them visible with Label1.Visible = Truewithin your conditional check.

How to select value from Google auto location using Selenium

How to automate this to select particular value even the dropdown list id cannot be inspected. Can anyone help me out on this?
Need to select U.S. 22 Imperial from the list
Please find the HTML snippet
I am unable to proceed more than this. Please help me out!
WebElement location = driver.findElement(By.id("selectbox-city-list2"));
location.sendKeys("us");
You could use sendKeys and send arrow down to select an option. Selecting one by one with the arrow down will highlight the value. You will be able to check the highlighted value using the CSS class of highlighting.
You can use ActionClass
using this you can move your cursor over a specific element based on coordinates and perform a click.
1.So taking the coordinates of that text box.
2.Enter the full value in the text box. ,
3.calculate a very near coordinate to that text box(so that it will be the suggestion) and perform a click.
element = xxxxxxx;
Actions builder = new Actions(driver);
builder.moveToElement(element, x_coord, y_coord).click().build.perform();

Mouse click/release psychopy

I am using the .isPressedIn() function see if the mouse click is in a target shape. However, whenever you click on the target shape, it will say the response is incorrect. However, whenever you hold the mouse button down in the target shape, it will say the mouse was clicked on the target. I'm not sure how to fix the mouse button release. I tried using CustomMouse, but I am unable to get that to click inside a shape (unless I am mistaken). Any suggestions would be greatly appreciated.
Thanks!
stimDuration = 5 #stimuli are on the screen for 5 seconds
potential_target = [shape1, shape2, shape3] #shapes that may be a target
target = random.sample(potential_target, 1) #randomly select a target
myMouse = event.Mouse() #define mouse
if clock.getTime() >= stimDuration
ResponsePrompt.draw() #message to indicate to participant to select target
win.flip()
core.wait(2)
if myMouse.isPressedIn(target[0]):
print "correct"
else:
print "incorrect"
The problem is that the line myMouse.isPressedIn(target[0]) checks the state of the mouse exactly when that line is run. Since it is preceeded by a core.wait(2) it does not react to mouse clicks in those two seconds and consequently only collects the mouse response of you still hold it down after two seconds.
I would instead have a tight loop around the myMouse.isPressedIn which runs thousands of times per second. So skipping your first lines:
ResponsePrompt.draw() # message to indicate to participant to select target
win.flip() # show that message
while True: # keep looping. We will break this loop on a mouse press
if myMouse.isPressedIn(target[0]): # check if click is within shape
print "correct"
break # break loop if this condition was met
elif myMouse.getPressed(): # check if there was any mouse press at all, no matter location
print "incorrect"
break # break while loop if this condition was met
In that code, you are using the expression if myMouse.isPressedIn(target[0]), but are only evaluating that expression after some time has elapsed (stimDuration). This means that isPressedIn() will be typically be evaluated well after the actual click happened. At that point, the mouse may no longer be within target[0], or may not longer be being pressed down by the subject. So I think what you are seeing is the correct (expected) behavior.
So to obtain the behavior that you want, you need to do keep track of whether then mouse was pressed in the shape on every frame.
Also, I am not sure how you are using the code you posted. Some looks appropriate for every frame, but some looks like it should be run only once (Begin routine). You might want to review that--things should not be initialized every frame (like target or myMouse).

QTP - Clicking on a button with a given value

I've started using QTP last weekend so I'm still a bit confused about some things.
I've coded a function that opens an URL on IE, performs some actions and writes a report. But I have a little problem: at a certain point the function has to click on a button to go on but this button's value is changed at every refresh of the page.
For example: at the first access the button's value (or label) is "Results List (51)" but, if I refresh the page, the value becomes "Results List (11)".
What changes is the number inside the brackets (that identifies the number of results inside the list).
Obviously I recorded the action only one time and the result is this:
Browser("myBrowser").Page("myPage").Frame("myFrame").WebButton("Results List 51)").Click
How can I click on the button without having to worry about it's value?
You should open the object repository and have a look at the description that was create for your WebButton then make the property in question a regular expression.
In your case the value should be Results List \(\d+\), this means Result List followed by open-parentheses, followd by one or more digits (a number) followed by close-parentheses.
Here's an explanation on how to use regular expressions in UFT.
This question reminded me of the days when I was a beginner in QTP ;) I think I still am!
Coming to your question -
If you don't really care about what is inside the brackets then you can just give Results List*.* but if you want to check if there is a bracket and digits within it then use the value suggested by Motti i.e. Results List (\d+)
Detailed Steps as you are a rookie:
1) Go to Resources->Object Repository
OR
In the Resources pane expand your action and double-Click the local object repository (You recorded hence the objects will be in local)
2) Click on the Concerned Object so that the object properties specific to this object is displayed.
3) Select the property (name?), at the extreme right you will see a button to configure the value, click on it.
4) Type the text Results List (\d+) or Results List*.*, select the checkbox for regular expressions.
5) A message box will appear, Click on No and then OK button.
Your script should run now!