1

driver.find_element(By.XPATH,'//body/div/div/div/div/div/div/div/div/div[2]/div/div/div/div/div/div/div/div[2]/div/div/input').send_keys(country)

This is the xpath for sending text in the dropdown of the facebook ad library report. It works well in window but when I run this selenium script in Linux machine (ec2---**.us-east-2.compute.amazonaws.com) it shows error in this line:

selenium.common.exceptions.NoSuchElementException: Message: no such element: Unable to locate element:

{"method":"xpath","selector":"//body/div/div/div/div/div/div/div/div/div[2]/div/div/div/div/div/div/div/div[2]/div/div/input"} ``

options = webdriver.ChromeOptions()

options.add_argument("--headless=new")

options.add_argument('--no-sandbox')

options.add_argument("--silent")

user_agent = 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/114.0.0.0 Safari/537.36'

options.add_argument("--disable-blink-features=AutomationControlled") options.add_experimental_option("excludeSwitches", ["enable-automation"]) options.add_experimental_option("useAutomationExtension", False)

options.add_argument('start-maximized')

options.add_argument("--window-size=1519.200,5471.890")

options.add_argument("--window-position=0,0")

options.add_argument('--disable-dev-shm-usage')

These are the arguments used.

Kindly given the solution for this

  • 2
    You really need to learn to build an Xpath on your own, these auto generated XPath's from Chrome are always going to be flaky. – BernardV Jun 22 '23 at 06:34
  • 2
    xpath syntax: https://www.w3schools.com/xml/xpath_syntax.asp cheatsheet: https://devhints.io/xpath – Knight Jun 22 '23 at 06:43

0 Answers0