Using Selenium WebDriver in Java: clicking at specific x and y coordinates

I am having trouble with clicking a Point in Flash Player within a Flash Iframe that is embedded in a browser. I want to click on a specific button, but I find it difficult to code for Flash and interact with Flash Elements.

Therefore, I would like to be able to click the coordinates (1170,230), with the assumption that 0,0 represents the top left corner of the browser page (excluding the address and bookmark bar).

I have attempted the following code, however, it is not functioning as expected.

WebDriverWait wait = new WebDriverWait(driver, 15);

WebElement knownElement1=wait.until(ExpectedConditions.elementToBeClickable(By.xpath("//*@id='game']")));

Actions builder1 = new Actions(driver); 
builder1.moveToElement(knownElement1, 1170, 230).click().perform();

Answer №1

Have you made the transition to the flash frame?

driver.switchTo().frame(frameWebElementInstance);

Remember to switch back when you need to perform actions outside of the frame

Answer №2

Give this a try:

int xCoordinate = 0; // specify the x-coordinate
int yCoordinate = 0; // specify the y-coordinate

WebElement elementToClick = driver.findElement(By.xpath("YOUR LOCATOR"));

JavascriptExecutor jsExecutor = (JavascriptExecutor) driver;
jsExecutor.executeScript("window.scroll(" + xCoordinate + ", " + yCoordinate + ");");
jsExecutor.executeScript("arguments[0].click();", elementToClick);

Hopefully, this solution works for you :)

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Creating an xpath with ::before and ::after pseudo-elements in selenium

Line 1 -> <input _ngcontent-huh-c120="" name="options" id="line" type="radio" ng-reflect-name="options" ng-reflect-model="0" ng-reflect-value="0" class="ng-untouched ng-valid ...

Is there a way to fully load the entire Django project, including all JS files, when running Selenium tests with webdriver?

I am currently using Selenium to conduct tests on the JavaScript in my Django project. Although the web driver successfully retrieves the index.html, which serves as the homepage, the JavaScript does not load properly within the page (as it would if I wer ...

Python: How to end a for loop when a certain number is reached?

I need to find a way to stop my for-loop at a specific point while iterating through a list. The traditional method using range() doesn't seem to work in this scenario. I must be missing something. Currently, I am storing this information globally: ...

What is the process for setting up SSL for Angular e2e testing?

I'm working on an Angular sample project that includes end-to-end tests focusing on OAuth2 and OIDC flows. I've noticed that the behavior of browsers varies when SSL/TLS is enabled or disabled. To ensure consistency, I would like to run my end-to ...

Capybara's attach_file function is not properly activating the React onChange handler in Firefox

Currently, I am conducting tests on the file upload feature of a React-built page. The page includes a hidden file input field with an onChange event listener attached to it. Upon selecting a file, the onChange event is triggered and the file is processed ...

No such element exception cannot be raised

Testing sometimes fails when an element cannot be found. I want to find a way to continue the test even if the element is not located. In trying to address this issue, I have implemented NoSuchElementException in my code snippet below: try { WebEleme ...

Creating a collection of web elements in Selenium using a list of webelements

I have multiple page elements and records with xpath or ids in the following format: //*[@id='xyz-model-car-card-0']/car //*[@id='xyz-model-car-card-1']/car //*[@id='xyz-model-car-card-2']/car I am trying to group these web ...

Tips for uploading files to Microsoft Edge using Selenium

I've been working on uploading files to a website using Selenium and encountered an issue specifically with Microsoft Edge. The code I'm using works perfectly in Firefox, Chrome, and Safari, but for some reason, it fails when running against Edg ...

Selenium webdriver cannot find the element within the JavaScript code

await driver.findElement(By.id('closeBtn')).click(); or await driver.findElement(By.xpath('//*[@id="closeBtn"]')).click(); When attempting to use the above conditions for a pop-up, it does not work as expected. An error is ...

Selenium in Python struggles to locate elements using a CSS selector based on class

Trying to identify and click on a specific element using 4 different approaches: The DOM structure is as follows: <div class="ui dropdown selection" tabindex="0"> I have attempted to locate the element using four methods: (By.XP ...

What is the most concise way to write this Xpath?

How can I retrieve the attribute value of an element using an absolute path like this: //*[@id="main"]/div[3]/div/div/div[3]/div[23]/div/div/div[1]/div/div/span/img I would like to know how to write code in relative xpath. Can you provide guidance on that ...

Verifying Page Modifications in Selenium Java - Confirming UI Adjustments

How can I effectively validate UI changes across all pages in the product, especially when new features are introduced or there are UI issues that need to be captured through automation using Selenium and Java? ...

Selenium is unable to locate an element using Jquery

sel.add_script( sel.get_location(), "jquery.js") #I am getting u'fd6c42bcc770ca9decc4f358df3688290a4257ad' idOfResultWithSomeImage=sel.get_eval("window.jQuery('#result').find('img').filter('[alt=SeleImage]') ...

Is there a way to show a string value stored in Java onto an Angular 8 display?

Hey there! I am just starting out with angular 8 and have a java project where I'm using JDBC to connect to my beloved MySQL database. I have some valuable data stored in a MySQL table that I access in java and store in strings (or even a list). Now, ...

Capturing Timeout error in selenium testing

Currently, I'm utilizing the PhantomJS webdriver in a C# WinForms project. One key difference between PhantomJS and Firefox is that PhantomJS will proceed with the code execution even if the webpage has not fully loaded. To ensure it runs only when t ...

"Selenium encounters a NoSuchElementException when trying to interact with a dropdown menu located inside an

I have been trying to access the voter list database through this link Unfortunately, I am unable to retrieve the first drop-down menu. I am currently using selenium version 3.14 This is the code that I have written: user_agent = "Mozilla/5.0 (X11; ...

Encountered a 403 error when attempting to scrape a website with Python using both requests and selenium

My current project involves scraping data from the website "https://coinatmradar.com/". To achieve this, I am utilizing a combination of requests, beautifulsoup, and selenium (when necessary). Unfortunately, my IP address was eventually blocked by the webs ...

Retrieve xPath and/or CSS Selector for a Python Selenium Element (not locate element by)

Is there a way to retrieve the xpath and css_selector of an element if I already have the element? To clarify, I am not looking for how to find an element using xpath or css_selector, but rather how to obtain these properties from an existing element. Th ...

PHP Selenium restricted by CORS Policy

I am encountering an error while trying to access a website using selenium. The error message is shown below: In an attempt to resolve the issue, I utilized the following code snippet: header('Access-Control-Allow-Origin: *');. However, this met ...

React-Collapsible Compilation Error

Currently, I am working on a project that involves Spring and ReactJS. I am still new to front-end development. One of the tasks I am trying to accomplish is creating a simple accordion using "REACT-COLLAPSIBLE". The code I have written is quite straight ...