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