0

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?

1 Answer 1

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

Sign up to request clarification or add additional context in comments.

4 Comments

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 , oh... I see... Did you check this answer ?
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 .
I tried the answers from the below link too. Not working stackoverflow.com/questions/11428026/…. @DonnyFlaw

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.