I want to do a right click on a link and move down the context menu . I have retrieved the location of the xpath(of the link) using the xpath.location and it gives.. let us say {'x': 28, 'y': 386} as coordinates. I want the mouse pointer to move to this coordinate and do a right click . For this I am using pyautogui.moveTo(28,386) .But the pointer is doing a right click at a different location and not on the link specified by the xpath. How can I click exactly on the link? Why are the coordinates specified by xpath.location different from those identified by the pyautogui?
Asked
Active
Viewed 1,067 times
1 Answers
0
As your problem seem to be X-Y issue I suggest you below solutions
You can do the same much easier:
1.
link = driver.find_element_by_xpath('<XPATH>')
driver.execute_script("arguments[0].setAttribute('target','_blank')", link)
link.click()
This will change target
attribute of link node to '_blank'
which imply to open link in new tab
P.S. Note that this code will physically make changes in DOM
2.
window.open(URL, "_blank", strWindowFeatures);
URL = link.get_attribute('href')
driver.execute_script('window.open(URL, "_blank";')
This allows to open URL in new tab

DonnyFlaw
- 581
- 3
- 9
-
thanks for the reply. I want to navigate through the context menu and select different options as needed. So how do i do that ? I think I should rewrite the question .Sorry for the confusion . The main focus is on getting contextclick and navigating through the menu – Lucky1234 Nov 24 '20 at 23:29
-
@Lucky1234 , oh... I see... Did you check [this answer](https://stackoverflow.com/questions/51619434/python-selenium-right-click/51619869#51619869) ? – DonnyFlaw Nov 24 '20 at 23:32
-
i tried using Actionchains.contextclick but it is not working. I am not able to view the context menu .Also i tried sending keys arrowdown and return but it is also not working .Thats when i came across pyautogui and thought to give it a try . It actually displays the context menu but not able to direct the location of the pointer to where i want it . – Lucky1234 Nov 24 '20 at 23:45
-
I tried the answers from the below link too. Not working https://stackoverflow.com/questions/11428026/select-an-option-from-the-right-click-menu-in-selenium-webdriver-java. @DonnyFlaw – Lucky1234 Nov 24 '20 at 23:51