An electronic device comprising: a housing; an antenna module disposed in the housing or forming a portion of the housing, and including a plurality of antenna elements and at least one sensor; a wireless communication circuit electrically or operatively connected to the antenna module, and configured to form a directional beam by using the antenna module; a processor operatively connected to the wireless communication circuit; and a memory operatively connected to the processor, and configured to store a number of measurements the number of measurements being defined for measuring, by using the directional beam, a strength of a plurality of beams having different directions and generated by at least one external electronic device, wherein the memory stores instructions that cause, when executed, the processor to: detect a state of the electronic device, by using the at least one sensor, based on at least one of a communication state of the electronic device, a location of the electronic device, and whether the electronic device is moving; select a search mode based on the detected state of the electronic device; determine the number of measurements based on the selected search mode; measure (405, 501), based on the number of measurements, a strength of a first beam generated by a first external electronic device by using a first directional beam formed in a first direction through the antenna module; and measure (407, 503), based on the number of measurements, a strength of a second beam generated by at least one of the first external electronic device or a second external electronic device by using a second directional beam formed in a second direction different from the first direction through the antenna module. a housing; an antenna module disposed in the housing or forming a portion of the housing, and including a plurality of antenna elements and at least one sensor; a wireless communication circuit electrically or operatively connected to the antenna module, and configured to form a directional beam by using the antenna module; a processor operatively connected to the wireless communication circuit; and a memory operatively connected to the processor, and configured to store a number of measurements the number of measurements being defined for measuring, by using the directional beam, a strength of a plurality of beams having different directions and generated by at least one external electronic device, wherein the memory stores instructions that cause, when executed, the processor to: detect a state of the electronic device, by using the at least one sensor, based on at least one of a communication state of the electronic device, a location of the electronic device, and whether the electronic device is moving; select a search mode based on the detected state of the electronic device; determine the number of measurements based on the selected search mode; measure (405, 501), based on the number of measurements, a strength of a first beam generated by a first external electronic device by using a first directional beam formed in a first direction through the antenna module; and measure (407, 503), based on the number of measurements, a strength of a second beam generated by at least one of the first external electronic device or a second external electronic device by using a second directional beam formed in a second direction different from the first direction through the antenna module. detect a state of the electronic device, by using the at least one sensor, based on at least one of a communication state of the electronic device, a location of the electronic device, and whether the electronic device is moving; select a search mode based on the detected state of the electronic device; determine the number of measurements based on the selected search mode; measure (405, 501), based on the number of measurements, a strength of a first beam generated by a first external electronic device by using a first directional beam formed in a first direction through the antenna module; and measure (407, 503), based on the number of measurements, a strength of a second beam generated by at least one of the first external electronic device or a second external electronic device by using a second directional beam formed in a second direction different from the first direction through the antenna module.